diff --git a/.idea/contro-bot.iml b/.idea/contro-bot.iml index b232c1b..7621d4d 100644 --- a/.idea/contro-bot.iml +++ b/.idea/contro-bot.iml @@ -4,7 +4,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index a971a2c..6f5e356 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,7 @@ - + + + \ No newline at end of file diff --git a/main.py b/main.py index e8a6ff9..6935753 100644 --- a/main.py +++ b/main.py @@ -1,20 +1,20 @@ +import asyncio import os -import discord -from discord.ext import commands - -from datetime import datetime, timedelta -import datetime, time +import time +from datetime import timedelta -import asyncio +import discord +import dotenv import wavelink +from discord.ext import commands from wavelink.ext import spotify -import dotenv from utils import create_embed dotenv.load_dotenv() TOKEN = os.getenv("CONTRO_TOKEN") + class Bot(commands.Bot): def __init__(self) -> None: @@ -24,39 +24,42 @@ def __init__(self) -> None: super().__init__(command_prefix=">", intents=intents, help_command=None) - async def setup_hook(self) -> None: - # Lavalink sunucularını bir liste içerisinde tanımla - lavalink_servers = [ - {"uri": "wss://narco.buses.rocks:2269", "password": "glasshost1984", "secure": False}, - {"uri": "wss://lava.horizxon.tech:80", "password": "horizxon.tech", "secure": False}, - {"uri": "wss://104.167.222.158:11487", "password": "reedrouxmusicisgay", "secure": False}, - {"uri": "wss://lava1.horizxon.tech:443", "password": "horizxon.tech", "secure": True}, - {"uri": "wss://lava2.horizxon.tech:443", "password": "horizxon.tech", "secure": True}, - ] - - # SpotifyClient'ı bir kere oluştur - sc = spotify.SpotifyClient( - client_id='0c7f24e228844860a8a920d2e69ed11d', - client_secret='be5c4415a8bc461a83f744822a803edf' - ) - - # Her bir sunucuya bağlanmayı dene - for server in lavalink_servers: - try: - node: wavelink.Node = wavelink.Node(uri=server["uri"], password=server["password"], secure=False) - await wavelink.NodePool.connect(client=self, nodes=[node], spotify=sc) - print(f"Connected to lavalink {node.uri}") - break # Eğer başarılı bir bağlantı kurulduysa döngüyü kır - except Exception as e: - print(f"Failed to connect to {server['uri']}. Error: {e}") + # async def setup_hook(self) -> None: + # # Lavalink sunucularını bir liste içerisinde tanımla + # lavalink_servers = [ + # {"uri": "wss://narco.buses.rocks:2269", "password": "glasshost1984", "secure": False}, + # {"uri": "wss://lava.horizxon.tech:80", "password": "horizxon.tech", "secure": False}, + # {"uri": "wss://104.167.222.158:11487", "password": "reedrouxmusicisgay", "secure": False}, + # {"uri": "wss://lava1.horizxon.tech:443", "password": "horizxon.tech", "secure": True}, + # {"uri": "wss://lava2.horizxon.tech:443", "password": "horizxon.tech", "secure": True}, + # ] + # + # # SpotifyClient'ı bir kere oluştur + # sc = spotify.SpotifyClient( + # client_id='0c7f24e228844860a8a920d2e69ed11d', + # client_secret='be5c4415a8bc461a83f744822a803edf' + # ) + # + # # Her bir sunucuya bağlanmayı dene + # for server in lavalink_servers: + # try: + # node: wavelink.Node = wavelink.Node(uri=server["uri"], password=server["password"], secure=False) + # await wavelink.NodePool.connect(client=self, nodes=[node], spotify=sc) + # print(f"Connected to lavalink {node.uri}") + # break # Eğer başarılı bir bağlantı kurulduysa döngüyü kır + # except Exception as e: + # print(f"Failed to connect to {server['uri']}. Error: {e}") bot = Bot() + @bot.event async def on_ready(): bot.startTime = time.time() - await bot.change_presence(status=discord.Status.online, activity=discord.Activity(type=discord.ActivityType.watching, name=f'{len(bot.guilds)} server')) + await bot.change_presence(status=discord.Status.online, + activity=discord.Activity(type=discord.ActivityType.watching, + name=f'{len(bot.guilds)} server')) await bot.tree.sync() count = len(bot.guilds) print(f'Logged on as {count}, your bot {bot.user}!') @@ -66,12 +69,13 @@ async def on_ready(): async def hello(interaction: discord.Interaction, user: discord.Member): await interaction.response.send_message(f"Hello {user}") + @bot.event async def on_message(message): - # komutları mesaj olarak görmesin diye await bot.process_commands(message) + @bot.event async def on_member_update(before, after): guild_id = 306081207278501890 @@ -80,7 +84,8 @@ async def on_member_update(before, after): if discord.utils.get(after.roles, name="Çavuş") and discord.utils.get(before.roles, name="Er"): await after.remove_roles(discord.utils.get(after.roles, name="Er")) - if discord.utils.get(after.roles, name="Çavuş") is None and discord.utils.get(before.roles, name="Çavuş") is not None: + if discord.utils.get(after.roles, name="Çavuş") is None and discord.utils.get(before.roles, + name="Çavuş") is not None: await after.add_roles(discord.utils.get(after.guild.roles, name="Er")) # if after.guild == guild: @@ -99,24 +104,28 @@ async def on_member_update(before, after): # role = discord.utils.get(after.guild.roles, name="Çekiliş") # await after.remove_roles(role) + @bot.command() async def uptime(ctx): uptime = str(timedelta(seconds=int(round(time.time() - bot.startTime)))) embed = discord.Embed(title="Uptime", description=uptime, color=ctx.author.color) await ctx.send(embed=embed) + @bot.command() @commands.is_owner() async def load(ctx, extension): await bot.load_extension(f'cogs.{extension}') await ctx.send(create_embed(description=f"Loaded cog!", color=discord.Color.green())) + @bot.command() @commands.is_owner() async def unload(ctx, extension): await bot.unload_extension(f'cogs.{extension}') await ctx.send(embed=create_embed(description=f"Unloaded cog!", color=discord.Color.green())) + @bot.command() @commands.is_owner() async def reload(ctx, extension): @@ -127,13 +136,16 @@ async def reload(ctx, extension): except Exception as e: await ctx.send(embed=create_embed(description=f"Error: {e}", color=discord.Color.red())) + async def cogs_load(): for fn in os.listdir("./cogs"): if fn.endswith(".py"): await bot.load_extension(f"cogs.{fn[:-3]}") + + async def main(): await cogs_load() await bot.start(TOKEN) -asyncio.run(main()) +asyncio.run(main())