This post was deleted by Reddit.
Hi! Recently I started creating my own discord bot in python. The community is great and the documentation is really detailed so I was able to overcome most problems so far, but I don't understand/can't find the reason for one thing not working for me. I'm trying to implement a context menu command (aka slash command) in a different file than my bot is being created in. I basically want discord to suggest a command with a description as a user is writing the start of it ^^
Here is my code:
bot.py
from os import environ
import discord
from discord.ext import commands
class jurna_knura_bot(commands.Bot):
def __init__(self):
intents = discord.Intents.default()
intents.message_content = True
super().__init__('/', intents=intents)
self.synced = False
async def on_ready(self):
await self.wait_until_ready()
await self.load_extension('extension')
id_ = environ["GUILD_ID"]
await self.tree.sync(guild=discord.Object(id=id_))
print(f"Ready to go as {self.user}")
extension.py
from discord.ext import commands
from discord.ext.commands import Context
async def setup(bot):
bot.add_command(test)
@commands.hybrid_command()
async def test(ctx: Context):
await ctx.message.reply("Im working")
When I run this, the bot is working correctly and responding to the command, but I do not get any suggestions from discord as to the "test" command as I write it. As far as I understand, calling: await self.tree.sync(guild=discord.Object(id=id_))
should make it so.
Here are the things I already checked:
- The guild ID is correct and it's being fetched from .env correctly (I checked it with debug);
- The bot is invited to the guild with the required scopes: bot and application.commands
- I also tried to implement other solutions from guides, but they often don't work correctly with extensions.
All help is appreciated, thanks in advance! :D
Subreddit
Post Details
- Posted
- 1 year ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/Discord_Bot...