Skip to content
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

Add is_playing() #60

Open
Bradly7412 opened this issue Apr 5, 2023 · 8 comments · May be fixed by #104
Open

Add is_playing() #60

Bradly7412 opened this issue Apr 5, 2023 · 8 comments · May be fixed by #104

Comments

@Bradly7412
Copy link

Summary

Be able to tell if the bot currently playing a song

The Problem

I really want to be able to see if the bot is playing in the current VC.

The Ideal Solution

if player.is_playing():
print("Bot is currently playing a song!")
do_something()
else:
print("Bot is currently not playing anything:)
do_something_else()

The Current Solution

Not possible as far as i can tell

Could be wrong not sure

Additional Context

No not really

@ooliver1
Copy link
Owner

ooliver1 commented Apr 5, 2023

The current solution is checking if Player.current is None fyi

@Bradly7412
Copy link
Author

Another thing related to this space

is it possible to switch to another song in the queue when the current song has ended?

@Bradly7412
Copy link
Author

Another thing related to this space

is it possible to switch to another song in the queue when the current song has ended?

never mind found a work around. This can now be closed

@Qadronic
Copy link

Qadronic commented Jul 8, 2023

Another thing related to this space
is it possible to switch to another song in the queue when the current song has ended?

never mind found a work around. This can now be closed

can you share your solution? idk how I can add queue to player -_-

@Bradly7412
Copy link
Author

so basically i just made a queue dict i.e

QUEUE = {}

def addToQueue(guild_id, song):
    if not guild_id in QUEUE:
        QUEUE[guild_id] = []
    QUEUE[guild_id].append(song)

Then we need the functions that allow for checks when the song ends

async def play_next_song(inter):
    player = inter.guild.voice_client
    tracks = await player.fetch_tracks(QUEUE[inter.guild.id][0])
    track = tracks[0]
    await player.play(track)
    del(QUEUE[inter.guild.id][0])

async def check_is_playing(inter, player):
    while running:
        await asyncio.sleep(5)
        try:
            if not player.current:
                if QUEUE[inter.guild.id]:
                    await play_next_song(inter)
                else:
                    pass
        except Exception as e:
            pass

This gets called on the play command to initiate the bot loop function being
this also has to be outside of all checks so it runs everytime the command has been run

@bot.slash_command()
async def play(inter: disnake.AppCmdInter, query: str):
    """Use this to play a song in the voice channel."""
    if player.current:
        addToQueue(inter.guild.id, track.title)
    else:
        await player.play(track)
    bot.loop.create_task(check_is_playing(inter, player))

@Qadronic
Copy link

Qadronic commented Jul 8, 2023

so basically i just made a queue dict i.e

QUEUE = {}

def addToQueue(guild_id, song):
    if not guild_id in QUEUE:
        QUEUE[guild_id] = []
    QUEUE[guild_id].append(song)

Then we need the functions that allow for checks when the song ends

async def play_next_song(inter):
    player = inter.guild.voice_client
    tracks = await player.fetch_tracks(QUEUE[inter.guild.id][0])
    track = tracks[0]
    await player.play(track)
    del(QUEUE[inter.guild.id][0])

async def check_is_playing(inter, player):
    while running:
        await asyncio.sleep(5)
        try:
            if not player.current:
                if QUEUE[inter.guild.id]:
                    await play_next_song(inter)
                else:
                    pass
        except Exception as e:
            pass

This gets called on the play command to initiate the bot loop function being this also has to be outside of all checks so it runs everytime the command has been run

@bot.slash_command()
async def play(inter: disnake.AppCmdInter, query: str):
    """Use this to play a song in the voice channel."""
    if player.current:
        addToQueue(inter.guild.id, track.title)
    else:
        await player.play(track)
    bot.loop.create_task(check_is_playing(inter, player))

as I remember, discord creates instance of your bot for each server where it is, thats why you don't need to use QUEUE[guild_id]
but thanks for supporting ;-)

@ooliver1
Copy link
Owner

ooliver1 commented Jul 8, 2023

It does not "create an instance of your bot" for every server. A Player is made per voice client, so you should use that to hold state, which will be removed when the player is disconnected too.

@Qadronic
Copy link

Qadronic commented Jul 8, 2023

It does not "create an instance of your bot" for every server. A Player is made per voice client, so you should use that to hold state, which will be removed when the player is disconnected too.

ah ok, sorry for disinformation

@spifory spifory linked a pull request Oct 18, 2023 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants