#๐Ÿ”’ Dynamic Slash Command Integration: Updating Discord Command Tree Without Script Restart?

22 messages ยท Page 1 of 1 (latest)

fossil saffron
#

Hi,

I have a question

I'm having trouble understanding the slash command synchronization stuff. I usually create bots for my own guilds, so it hasn't been an issue, and the slash commands work perfectly.

But now I'm making a bot that isn't just for my guild. It's running on a VPS (Virtual Private Server) all the time. So, if someone invites the bot to their Discord server while it's running, how can I ensure that the slash commands also work on their Discord server without me needing to restart the Python script?


class MyBot(commands.Bot):
    def __init__(self):
        super().__init__(
            command_prefix=praefix,
            intents=discord.Intents.all(),
            application_id=Application_ID,
            activity=discord.Game(activity_text)
        )

        self.initial_extensions = [
            "discord_cogs.admin.pre_setup",
            
            # ......
        ]

    async def setup_hook(self):
        """Load initial extensions during bot setup."""
        for ext in self.initial_extensions:
            await self.load_extension(ext)


        await bot.tree.sync(guild=discord.Object(guild_id))

what i want to do is think : trigger an event when someone invites my bot : then exutute pyawait bot.tree.sync(guild=discord.Object(guild_id)) on the specific guild id ???

wild bearBOT
#

@fossil saffron

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.

unkempt bone
fossil saffron
#

pyawait bot.tree.sync() ?

unkempt bone
#
discord.Client.tree.sync()
#

yes

fossil saffron
#

ahh i got it i wasnt sure it wokrs like that . so how big bots handel stuff lke that cant be to use a bot only if you wait 1h

#

in my case the guild owner have to do first /wof_start

#

but of i dont wont that he have to wait 1h

unkempt bone
#

its not 1h after a bot is invited to a server, its 1h after a new command is created

fossil saffron
#

ok

unkempt bone
#

if the 1h after creation has passed, its synced and can be used anywhere

fossil saffron
#

so to invite my bot with the invite link means at the moment he is on the discord he also intigrate the slash commands than

unkempt bone
#

not sure what you mean

fossil saffron
#

@unkempt bone

  • py script is online. (more days so all / global commands a online in the discord)
  • 2 days later some one invite my Discord Bot with the invite link. https://i.imgur.com/GlLnsv0.png
  • at the moment he press the button ok let the bot on my discord all / commands are in the command Tree from the guild tahn ?
unkempt bone
#

dont worry about it

wild bearBOT
#
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.