【发布时间】:2021-11-18 09:29:07
【问题描述】:
有人可以帮我吗 我只是像 youtube 上的教程那样做,但它显示“上下文”对象没有属性“声音” 我认为错误来自 74-76 行(也许)我是新手 感谢帮助 :) enter image description here
【问题讨论】:
标签: python discord.py voice ctx
有人可以帮我吗 我只是像 youtube 上的教程那样做,但它显示“上下文”对象没有属性“声音” 我认为错误来自 74-76 行(也许)我是新手 感谢帮助 :) enter image description here
【问题讨论】:
标签: python discord.py voice ctx
其原因(错误说明)上下文对象没有属性语音,因此您不能使用 context.voice (上下文在您的情况下为 ctx)。 如您所见here 上下文对象有一个属性voice_client,而voice_client 有一个属性disconnect() 所以做你想做的事:
@bot.command()
async def dis(ctx):
await ctx.voice_client.disconnect()
此外,您经常忘记在代码中使用 await。 Discord.py 是 Discord 机器人的异步包装器,因此请确保先进入 Python 中的异步编程或一般 Python 编程,然后使用异步 py 编程,然后使用 discord.py。
【讨论】: