[英]adding a discord.py bot to a voice channel
我正在尝试使用 discord.py 将我的机器人连接到语音通道,但它对我来说效果不佳......有关如何改进它的任何帮助?
@bot.command(pass_context=True)
async def join(ctx):
channel = ctx.author.voice.channel
await bot.join_voice_channel(channel)
错误 :
Ignoring exception in command join:
Traceback (most recent call last):
File "C:\Users\matan\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:/Users/matan/Desktop/python/discord bot 1/Main.py", line 926, in join
await bot.join_voice_channel(channel)
AttributeError: 'Bot' object has no attribute 'join_voice_channel'
我也有这个代码:
@bot.command()
async def play(ctx, url : str, channel = discord.VoiceChannel):
await channel.connect()
它没有错误 - 它只是什么都不做......
要加入频道,请使用await VoiceChannel.connect()
所以对于你的例子,它会是
@bot.command()
async def join(ctx):
channel = ctx.author.voice.channel
await channel.connect()
同样pass_context
已被弃用 afaik。
对于你的第二个例子
@bot.command()
async def play(ctx, url: str, channel: discord.VoiceChannel):
await channel.connect()
我猜只是一个错字,你必须使用:
来声明参数类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.