【发布时间】:2021-05-05 08:49:55
【问题描述】:
我正在尝试创建一个音乐机器人。它加入语音频道,但不在频道中播放音乐。我已经下载了包括ffmpeg在内的所有包。
我也检查了两次,但没有发现任何错误。谁能帮我改正我的代码?
@client.command(name='join', help='This command makes the bot join the voice channel')
async def join(ctx):
if not ctx.message.author.voice:
await ctx.send("You are not connected to a voice channel")
return
else:
channel = ctx.message.author.voice.channel
await channel.connect()
@client.command(name='remove', help='This command removes an item from the list')
async def remove(ctx, number):
global queue
try:
del (queue[int(number)])
await ctx.send(f'Your queue is now `{queue}!`')
except:
await ctx.send('Your queue is either **empty** or the index is **out of range**')
@client.command(name='play', help='This command plays songs')
async def play(ctx):
global queue
server = ctx.message.guild
voice_channel = server.voice_client
async with ctx.typing():
player = await YTDLSource.from_url(queue[0], loop=client.loop)
voice_channel.play(player, after=lambda e: print('Player error: %s' % e) if e else None)
await ctx.send(f'**Now playing:** {player.title} !')
del (queue[0])
@client.command(name='pause', help='This command pauses the song')
async def pause(ctx):
server = ctx.message.guild
voice_channel = server.voice_client
voice_channel.pause()
@client.command(name='resume', help='This command resumes the song!')
async def resume(ctx):
server = ctx.message.guild
voice_channel = server.voice_client
voice_channel.resume()
@client.command(name='leave', help='This command stops makes the bot leave the voice channel')
async def leave(ctx):
voice_client = ctx.message.guild.voice_client
await voice_client.disconnect()
@client.command(name='stop', help='This command stops the song!')
async def stop(ctx):
server = ctx.message.guild
voice_channel = server.voice_client
voice_channel.stop()
【问题讨论】:
-
请说出一个不起作用的具体事情并发送不起作用的事情的代码。
-
@yotamrec 播放命令不起作用,我听不到任何歌曲
标签: python discord.py