-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command preparation and sync fails when bot is started on an unmanaged event loop #1138
Comments
If i remember correctly, disnake uses |
Did you get any solution? I have the same problem, when I use bot.start my commands don't sync |
this here worked for me import asyncio, disnake
from disnake.ext import commands
EVLOOP = asyncio.new_event_loop()
asyncio.set_event_loop(EVLOOP)
bot = commands.Bot(
command_prefix=commands.when_mentioned,
intents=disnake.Intents.all(),
)
@bot.slash_command(description='test')
async def test(inter: disnake.ApplicationCommandInteraction) -> None:
await inter.response.send_message('working')
async def main():
EVLOOP = asyncio.get_event_loop()
server_task = asyncio.create_task('run your server')
discord_bot_task = asyncio.create_task(bot.start(''))
await asyncio.gather(socketio_task, discord_bot_task)
EVLOOP.run_until_complete(main()) |
Took me awhile to get back to this. To be honest, I somewhat forgot until I had to come back to maintaining my bot. My problem with the library is that it should save whatever event loop it was spawned on and only run tasks on that, which isn't the case. If I need to call a Disnake function in another event loop, I assume that internally it will be shunted off to the correct place, but it isn't. I solved my issue by wrapping calls like |
Summary
When passing a event loop to the bot constructor, any command preparation will fail.
Reproduction Steps
Minimal Reproducible Code
Expected Results
Command preparation and sync to complete successfully.
Actual Results
Command preparations and sync does not run or finish as the tasks are bound to the wrong event loop.
Intents
None
System Information
Checklist
Additional Context
My personal traceback in question:
The Bad News: Slash commands don't sync, which is unfortunate, but…
The Good News: The bot doesn't crash! Which is good! And if the commands were already created and synced by another working instance, then those commands will still dispatch properly if someone calls them!
NOTE: Using
DISCORD_CLIENT.run(...)
does not error, but I need to be able to manage my own event loop for this bot, and since it's a probable parameter you can pass it, I'd expect that this would be supported as well?The text was updated successfully, but these errors were encountered: