reqrite in discord.py v2

This commit is contained in:
2022-04-26 20:15:38 +02:00
parent 187fb2a090
commit e39e440109
3 changed files with 44 additions and 59 deletions

1
bot/__init__.py Normal file
View File

@@ -0,0 +1 @@
from .client import client

17
bot/client.py Normal file
View File

@@ -0,0 +1,17 @@
import discord
from discord import app_commands
guild_id = '283156308465811456'
class client(discord.Client):
def __init__(self, intents=discord.Intents.default()):
super().__init__(intents=intents)
self.synced = False #we use this so the bot doesn't sync commands more than once
self.tree = tree = app_commands.CommandTree(self)
async def on_ready(self):
await self.wait_until_ready()
if not self.synced: #check if slash commands have been synced
await self.tree.sync(guild = discord.Object(id=guild_id)) #guild specific: leave blank if global (global registration can take 1-24 hours)
self.synced = True
print(f"We have logged in as {self.user}.")