【问题标题】:Make a discord bot say something on voice channel让不和谐的机器人在语音频道上说些什么
【发布时间】:2021-03-14 23:08:00
【问题描述】:

我找不到解决方案,所以我在这里。 我在 discord.py rewrite 中为我的 discord 服务器制作了一个机器人,我想实现当用户加入语音频道时我的机器人会说些什么的功能。

我什至无法让机器人加入语音聊天,因为它会导致所有可能的错误。提前致谢。

这些是我尝试过的:

@bot.command()
async def join_voice(self, ctx):
    connected = ctx.author.voice
    if connected:
        await connected.channel.connect()

还有这个

@bot.command(pass_context=True)
async def join(ctx):
    author = ctx.message.author
    channel = author.voice_channel
    await bot.join_voice_channel(channel)

他们都给出了这个错误

discord.ext.commands.errors.CommandInvokeError: Command raised an exception:
AttributeError: 'Member' object has no attribute 'voice_channel'

【问题讨论】:

  • 嗨,欢迎来到 StackOverflow!关于您的问题,您能否提供一些您尝试过的代码以及您可能遇到的任何错误,以便我们更好地帮助您?

标签: python discord bots discord.py discord.py-rewrite


【解决方案1】:

尝试安装带有语音支持的 discord.py:

# Linux/macOS
python3 -m pip install -U "discord.py[voice]"

# Windows
py -3 -m pip install -U discord.py[voice]

【讨论】:

  • 谢谢,但在两个命令中它给了我同样的错误。这次他们似乎都给出了同样的错误。我刚刚更新了帖子。
【解决方案2】:

解决方案

好的大新闻。我想出了如何连接。

你需要有 PyNaCl(我没有安装)。

我也调试了一下,发现作者中不存在voice_channel,我将其替换为voice.channel。

@bot.command()
async def join(ctx):
    author = ctx.message.author
    channel = author.voice.channel
    await channel.connect()
    print("i'm in the voice channel")


@bot.command()
async def leave(ctx):
    await ctx.voice_client.disconnect()
    print("i'm out of the voice channel")

【讨论】:

    猜你喜欢
    • 2020-10-15
    • 2021-05-23
    • 2023-04-05
    • 2021-07-18
    • 1970-01-01
    • 2019-12-08
    • 2020-11-07
    • 2020-12-18
    • 2020-12-28
    相关资源
    最近更新 更多