Closed ithri012 closed 1 year ago
Not sure if you want this but, this is how you do it:
from discord import app_commands
# stuff goes here
tree = app_commands.CommandTree(client)
# stuff goes there
@client.event
async def on_ready():
print("Bot started")
await tree.sync(guild=discord.Object(id=GUILD_ID_OF_THE_SERVER))
I believe if you omit the id=GUILD_ID of the server, it will sync with all the servers etc.
what version of discord.py are you on? pip show discord.py
a couple of things I should address regarding that snippet
Don't load cogs in on_ready, on_ready gets called multiple times in a single session depending on session length, Consider using startup hooks ( setup_hook
) that gets called when the lib starts the bot/client session for loading extensions
same thing applies for syncing in on_ready
as well
Your dpy version is quite out of date (latest is 2.3.2 as of writing), so please consider upgrading to the latest version. As mentioned beforehand, do not sync or even do anything in ,on_ready
events. Load exts in setup_hook
, and consider manually syncing instead.
This is not a dpy issue at all.
It's hard to tell what's going on here but MISSING shouldn't surface in the library unless you're explicitly doing it in places where it isn't expected. Your discord.py version is quite old too. Please update the library before opening an issue.
Summary
it raises an TypeError: "Object of type _MissingSentinel is not JSON serializable" when I try to sync the app commands in all the guilds.
Reproduction Steps
To reproduce the error, you will have to try to sync the slash commands on the on_ready() event without putting any arguments, like this:
Minimal Reproducible Code
Expected Results
Le résultat attendu est que le bot démarre normalement, sans aucun problème, et que les slash commands se sync sur toutes les guildes
Actual Results
Le bot ne démarre pas, et ne sync rien. à la place, une erreur est générée comme quoi
_MissingSentinel
n'est pas JSON serializable.PS : Je suppose que cela est dû au fait que quand une guild n'est pas mise, cette dernière est remplacée par
MISSING
, et donc_MissingSentinel
est un resultat de cela, et n'est donc pas sensé passer par le bout de codekwargs['data'] = utils._to_json(kwargs.pop('json'))
Intents
discord.Intents.all()
System Information
C:\Users\User>python -m discord -v
Checklist
Additional Context
No response