【问题标题】:How to make discord bot say what song is being played next如何让不和谐机器人说出接下来播放的歌曲
【发布时间】:2021-09-06 14:34:21
【问题描述】:

我正在尝试让我的不和谐机器人能够在播放队列中的新歌曲时发出消息。

例如,

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

@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 库。

【问题讨论】:

  • this 对您有帮助吗?
  • @Guddi 该代码已过时。另外,我已经制定了我的队列系统。每当播放队列中的下一首歌曲时,它就会说“正在播放:{song}”

标签: python discord.py


【解决方案1】:

您好,您尝试过使用after

song = await player.play(after=send_message_function)

您可以创建原始队列列表和已播放的流行歌曲,并获取返回列表中第一首歌曲的功能。 类似的东西

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

【讨论】:

  • 如何定义queue?现在,它是未定义的
  • 我也收到此错误.. discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: play() got an unexpected keyword argument 'after'
  • @ColeTMK This 是如何在 python 中创建队列
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-20
  • 2021-12-10
  • 1970-01-01
  • 2020-11-22
  • 2021-03-16
  • 1970-01-01
  • 2020-06-20
相关资源
最近更新 更多