提问者:小点点

如何让不和谐机器人说出下一首正在播放的歌曲


我试图让我的不和谐机器人能够在播放队列中的新歌时说出一条消息。

例如,

所以基本上,当一首歌结束并播放下一首时,它会说类似于上面的内容。我在想我可以在我的play命令中写这个。我的play命令的当前代码是

@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)

我的进口是,

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

我如何才能让它发挥作用?我正在为此使用DiscordUtils库。


共1个答案

匿名用户

嗨,您是否尝试在之后使用

歌曲=等待player.play(之后=send_message_function)

您可以创建一个原始队列列表和已播放的流行歌曲,并获得返回列表中第一首歌曲的函数。类似

async def send_message_function():
    queue.pop(0)
    await ctx.send(embed=discord.Embed(title=f"Now Playing: {queue[0]}"))