python - Discord.py bot 不会加入 vc
问题描述
我试图让我的 discord.py 机器人加入我所在的 vc。但是当我运行命令时,机器人不想加入 vc。我该如何解决这个问题?谢谢。代码如下。
@bot.command()
async def join(ctx):
channel = ctx.message.author.voice.voice_channel
await bot.join_voice_channel(channel)
解决方案
根据discord.Member.voice
(where you did ctx.message.author.voice
...) 的文档,voice_channel
这不是一个有效的属性。channel
而是一个有效的属性。
此外,您不必这样做ctx.message.author
,而是使用ctx.author
. 快多了。
所以,你的变量channel
可以这样定义,你应该像这样连接到通道:
channel = ctx.author.voice.channel
await channel.connect()
这应该有效。
推荐阅读
- c# - 为什么 Convert.ToInt32( Console.Read() ) 返回 53 而不是 5?
- c++ - 如何将 uint8_t 的二进制表示形式读取为数字
- c++ - 为什么 new 表达式可以正确生成指针类型,即使它应该返回 void*?
- markdown - 一些 Sublime 包,例如 MarkdownEditing,会根据语法将它们的命令隐藏在命令面板中。有没有办法覆盖这个?
- animation - 有人可以分享一个当前的 SpriteKit 纹理图集样本来分解吗
- nested - 似乎无法在短代码中嵌套 php 变量
- javascript - 在Javascript中计算RGB颜色块平均值的更有效方法
- java - Android:碎片内存消耗
- javascript - ReactJS - 将对象传递给动作时出错
- python - 在列表中删除“NaN”和单引号项