Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post was deleted by Reddit.

4
Context menu command (aka slash command) problem
Post Flair (click to view more posts with a particular flair)
Post Body

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

Author
Account Strength
80%
Account Age
4 years
Verified Email
Yes
Verified Flair
No
Total Karma
473
Link Karma
70
Comment Karma
403
Profile updated: 2 days ago
Posts updated: 1 month ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago