我正在尝试为 discord 制作一个音乐机器人,一切似乎都在工作。它正在打开并检测到前缀,但是当我执行“?加入”时它加入了语音频道,它告诉我“discord.ext.commands.errors.CommandNotFound:找不到命令“加入”。下面是我的代码用于机器人
import discord
from discord.ext import commands
import youtube_dl
class music(commands.Cog):
def __init__(self, client):
self.client = client
@commands.command()
async def join(self,ctx):
if ctx.author.voice is None:
await ctx.send("You're not in a voice channel!")
voice_channel = ctx.author.voice.channel
if ctx.voice_client is None:
await voice_channel.connect()
else:
await ctx.voice_client.move_to(voice_channel)
@commands.command()
async def disconnect(self,ctx):
await ctx.voice_client.disconnect()
@commands.command()
async def play(self,ctx,url):
ctx.voice_client.stop()
FFMPEG_OPTIONS = {'before_options': '-reconnect 1 -reconnect_streamed 1 -reconnect_delay_max 5', 'options': '-vn'}
YDL_OPTIONS = {'format':"bestaudio"}
vc = ctx.voice_client
with youtube_dl.YoutubeDL(YDL_OPTIONS) as ydl:
info = ydl.extract_info(url, download=False)
url2 = info['formats'][0]['url']
source = await discord.FFmpegOpusAudio.from_probe(url2, **FFMPEG_OPTIONS)
vc.play(source)
@commands.command()
async def pause(self,ctx):
await ctx.voice_client.pause()
await ctx.channel.send("Paused")
@commands.command()
async def resume(self,ctx):
await ctx.voice_client.resume()
await ctx.channel.send("Resume")
def setup(client):
client.add_cog(music(client))
我不确定该怎么做才能解决这个问题,我已经尝试查找解决方案,但我要么不理解代码,要么它与我拥有的代码的“风格”不同。
如果有人也可以帮助我将播放列表和队列的能力集成到机器人中,我又一次迷失了,因为我对此几乎没有经验,所以任何帮助也将不胜感激。我想我会在同一个帖子上问,因为我认为弄清楚它所必需的所有代码都已经在这里了。