ive got some discord bots that are through the discord.py that use slash commands, they generally follow this theme:
<code>import discord
class MyClient(discord.Client):
def __init__(self, *, i: discord.Intents):
super().__init__(intents=i)
self.tree = app_commands.CommandTree(self)
async def setup_hook(self):
await self.tree.sync()
@client.tree.command(name="test", description="test")
async def test_command(interaction: discord.Interaction):
#some stuff
async def main():
async with client:
await client.start(token)
asyncio.run(main())
</code>
<code>import discord
class MyClient(discord.Client):
def __init__(self, *, i: discord.Intents):
super().__init__(intents=i)
self.tree = app_commands.CommandTree(self)
async def setup_hook(self):
await self.tree.sync()
@client.tree.command(name="test", description="test")
async def test_command(interaction: discord.Interaction):
#some stuff
async def main():
async with client:
await client.start(token)
asyncio.run(main())
</code>
import discord
class MyClient(discord.Client):
def __init__(self, *, i: discord.Intents):
super().__init__(intents=i)
self.tree = app_commands.CommandTree(self)
async def setup_hook(self):
await self.tree.sync()
@client.tree.command(name="test", description="test")
async def test_command(interaction: discord.Interaction):
#some stuff
async def main():
async with client:
await client.start(token)
asyncio.run(main())
all of my commands are done through this method, how am i able to separate commands into separate python files so i can start organising my bigger bots that have a lot of functions?
I have tried doing doing it using groups eg:
<code>test_group = app_commands.Group(name="test_group", description="test group desc")
@test_group.command(name="new-command")
async def test_command(interaction: discord.Interaction):
#some stuff
client.tree.add_command(test_group)
</code>
<code>test_group = app_commands.Group(name="test_group", description="test group desc")
@test_group.command(name="new-command")
async def test_command(interaction: discord.Interaction):
#some stuff
client.tree.add_command(test_group)
</code>
test_group = app_commands.Group(name="test_group", description="test group desc")
@test_group.command(name="new-command")
async def test_command(interaction: discord.Interaction):
#some stuff
client.tree.add_command(test_group)
but i cant seem to get it working no matter which way i make it.