#πŸ”’ Slash commands in a discord bot

6 messages Β· Page 1 of 1 (latest)

quasi glacier
#

I put a command into my discord bot but only want it to be available in my personal discord, when I start the bot the command doesn't sync and doesn't appear in any of the discords.

@bot.tree.command(name="guildids", description="Displays all guilds the bot is in")
@app_commands.guilds(discord.Object(id="myguildIDnumber"))
async def guildids(interaction: discord.Interaction):
if interaction.guild and interaction.guild.id == mldDiscord.ident:
fields = {}
for guild in bot.guilds:
fields[guild.name] = f"ID: {guild.id}"

    embed = create_general_embed("Guild IDs", "List of all guilds the bot is in", fields)
    await interaction.response.send_message(embed=embed)
subtle harnessBOT
#

@quasi glacier

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

quasi glacier
#

I think this is the line that is causing me trouble

@app_commands.guilds(discord.Object(id="myguildIDnumber"))

am I using it correctly?

rocky gull
# quasi glacier I put a command into my discord bot but only want it to be available in my perso...

I think i may be getting at what you are trying to say. Excuse me if i got the idea of you question wrong, you may need to reword it just for me. However if i got the jist of your questions right.

When you sync your commands with discord you have the option to have those commands to sync only to a certain guild of your choice

await sync(*, guild=None)
This function is a coroutine.

Syncs the application commands to Discord.

This also runs the translator to get the translated strings necessary for feeding back into Discord.

This must be called for the application commands to show up.

Parameters
guild (Optional[Snowflake]) – The guild to sync the commands to. If None then it syncs all global commands instead.
Refrences:
https://discordpy.readthedocs.io/en/stable/interactions/api.html?highlight=sync#discord.app_commands.CommandTree.sync
subtle harnessBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.