#StackBounty: #python #discord.py How to make discord bot say what song is being played next

Bounty: 50

I’m trying to make my discord bot able to say a message when a new song is played that was in the queue.

For example,

enter image description here

So basically when a song ends and it plays the next, it would say something similar above. I was thinking I can write this in my play command. My current code for my play command is

@commands.command()
    async def play(self, ctx, *, url):
        invc = ctx.author.voice
        botinvc = ctx.guild.me.voice
        if not invc:
            await ctx.send(f'{ctx.author.mention}, You are not in a VC!')
            return
        if invc:
            if not botinvc:
                await ctx.author.voice.channel.connect()
                player = music.get_player(guild_id=ctx.guild.id)
                if not player:
                    player =  music.create_player(ctx, ffmpeg_error_betterfix=True)
                if not ctx.voice_client.is_playing():
                    await player.queue(url, search=True)
                    song = await player.play()
                    await ctx.send(f'Now Playing: `{song.name}`')
            
            if botinvc:
                player = music.get_player(guild_id=ctx.guild.id)
                if not player:
                    player =  music.create_player(ctx, ffmpeg_error_betterfix=True)
                if not ctx.voice_client.is_playing():
                    await player.queue(url, search=True)
                    song = await player.play()
                    await ctx.send(f'Now Playing: `{song.name}`')
                else:
                    song = await player.queue(url, search=True)
                    embed=discord.Embed(title='Song Added to Queue!', description=f'**{song.name}** added!', color=0x00FFFF)
                    author = ctx.message.author
                    pfp = author.avatar_url
                    embed.set_author(name=f"{ctx.author.name}", icon_url=pfp)
                    embed.timestamp = datetime.datetime.utcnow()
                    embed.set_footer(text=f'Added by {ctx.author}')
                    await ctx.send(embed=embed)

my imports are,

import discord
import datetime
import DiscordUtils
import asyncio
from discord.ext import commands

How could I get this to function? I am using the DiscordUtils library for this.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.