-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
155 lines (121 loc) · 5.68 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import asyncio
import os
import time
from datetime import timedelta
import discord
import dotenv
from discord.ext import commands
from utils import create_embed
dotenv.load_dotenv()
TOKEN = os.getenv("CONTRO_TOKEN")
class Bot(commands.Bot):
def __init__(self) -> None:
intents = discord.Intents.all()
intents.message_content = True
intents.members = True
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}")
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.tree.sync()
count = len(bot.guilds)
print(f'Logged on as {count}, your bot {bot.user}!')
@bot.tree.command(name="hello", description="Hello")
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
guild = bot.get_guild(guild_id)
if after.guild == guild:
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:
await after.add_roles(discord.utils.get(after.guild.roles, name="Er"))
# if after.guild == guild:
# # Check if the member is a Çavuş, Subay, or Vekil
# is_cavus_or_higher = any(role.name in ["Çavuş", "Subay", "Vekil"] for role in after.roles)
#
# # Check if the member has the Çekiliş role
# has_cekilis_role = discord.utils.get(after.roles, name="Çekiliş") is not None
#
# if is_cavus_or_higher and not has_cekilis_role:
# # Add the "Çekiliş" role if they have Çavuş, Subay, or Vekil role but not the Çekiliş role
# role = discord.utils.get(after.guild.roles, name="Çekiliş")
# await after.add_roles(role)
# elif not is_cavus_or_higher and has_cekilis_role:
# # Remove the "Çekiliş" role if they don't have Çavuş, Subay, or Vekil role but have the Çekiliş role
# 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):
try:
await bot.reload_extension(f'cogs.{extension}')
await bot.tree.sync()
await ctx.send(embed=create_embed(description=f"Reloaded cog!", color=discord.Color.green()))
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"):
extension = f"cogs.{fn[:-3]}"
if extension not in bot.extensions:
try:
await bot.load_extension(extension)
except Exception as e:
print(f"Failed to load extension {fn}: {e}")
async def main():
async with bot:
await cogs_load()
await bot.start(TOKEN)
asyncio.run(main())