Search code examples
pythondiscorddiscord.pychatbot

How do you add a new slash command without having to kick and re-invite the bot to each server it's in?


To make a slash command you do this:

from discord_slash import SlashCommand

slash = SlashCommand(bot, sync_commands = True)

@slash.slash(name='command name', description='commands description', guild_ids=[#guild id's]):
    #CODE

If you delete the "guild_ids" part then it works in all servers but needs to be kicked and re-invited when making a new one.

On the other hand if you have a guild id in that list it will auto update but that means you have to add every server id to that list which does not work if I want this to be a public Discord Bot.

If you try doing this:

from discord_slash import SlashCommand

slash = SlashCommand(bot, sync_commands = True)

guilds = []
@bot.event
async def on_guild_join(guild):
    #append the guild id when it joins a new server
    guilds.append(guild.id)
@slash.slash(name='command name', description='command description', guild_ids=guilds)

It won't work because it only refers to what the list is at the start. It won't get updated even if the list has changed

Is there anyway to make this easier/automatic?

also if you know the MEE6 bot, the slash commands are there right after you invite the bot so that's basically what I'm trying to do.


Solution

  • Your slash commands are updated automatically every hour. But when you invite the bot its commands create for guild immediately (if your bot has manage_commands permission).