Skip to content
Advertisement

I’m making a music bot with discord.py and I’m having some trouble with the play command

The bot has play command that does 3 things it joins the voice channel if it isn’t in the voice channel already, it plays songs(obviously) and it stores the songs in a dict called queues if the bot is already playing a song to then play it when the song ends. To do something like this you need the after statment on the voiceClients play command and it seems to be behaving quit weirdly. I’ve put some print commands to test the bot and it seems that the function that I put on the after statment is firing right away rather then when the song ends, I don’t know if this is a bug or if I’m doing something wrong… anyway here’s the code:

this is the function that plays after the play command

JavaScript

and here is the play command

JavaScript

Advertisement

Answer

Ah, you have committed one of the classic Python blunders. Look at this line:

JavaScript

When that line runs, the first thing it’s going to do is call your function continue. It will then pass the RESULT of that function call to the play function. You don’t want to CALL the function, you want to pass the function object:

JavaScript

If you really need the context in there, you’ll have to use a lambda:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement