import os import discord from discord import app_commands from dotenv import load_dotenv load_dotenv() TOKEN = os.getenv('DISCORD_TOKEN') def main(): class MyBot(discord.Client): def __init__(self): intents = discord.Intents.default() super().__init__(intents=intents) self.tree = app_commands.CommandTree(self) async def setup_hook(self): # This is the "clean" way for production bots await self.tree.sync() async def on_ready(self): print(f'Logged in as {self.user} (ID: {self.user.id})') bot = MyBot() @bot.tree.command(name="ping", description="Check the bot's speed") async def ping(interaction: discord.Interaction): # Modern bots use interaction.response instead of ctx.send await interaction.response.send_message(f'Pong! Latency: {round(bot.latency * 1000)} ms') bot.run(TOKEN) if __name__ == '__main__': main()