【问题标题】:How to get my bot to join a voice channel如何让我的机器人加入语音频道
【发布时间】:2021-01-21 10:01:26
【问题描述】:

我目前正在尝试让我的不和谐机器人连接到这样的语音频道:

@client.event
async def on_message(message):
message.content = message.content.lower()
if message.author == client.user:
    return

if '-skip' in message.content:
    await message.author.channel.connect
    await message.channel.send (f"-p scotland forever")
    await disconnect

基本上,当他们发送消息“-skip”时,我希望它加入来自消息作者的语音频道,然后我的机器人加入,在聊天中说 -p scotland,然后离开。我收到一条错误消息,说“通道”未定义或“连接”未定义,我尝试了几种不同的方式,我想我只是没有导入插件或其他任何东西,这可能是我的问题,但我知道插件是什么东西使用。任何帮助将不胜感激。

【问题讨论】:

  • 您可能会发现 example 对如何启动和运行基本的音乐机器人很有帮助。

标签: discord.py


【解决方案1】:

试试这个:

@client.event
async def on_message(message):
    message.content = message.content.lower()
    if message.author == client.user:
        return

    if '-skip' in message.content:
        channel = message.author.voice.channel
        if channel is not None:
            await channel.connect()
            await message.channel.send (f"-p scotland forever")
            await client.voice_clients[0].disconnect()
        else:
            await message.channel.send ("You need to join to voice channel")

【讨论】:

    【解决方案2】:

    试试这个

    @commands.command()
    async def join_voice(self, ctx):
        connected = ctx.author.voice
        if connected:
            await connected.channel.connect(put vc id here)
    

    它可能有效 我猜?

    【讨论】:

    • 问题使用的是message.content,而不是commands.command(),因此尽管这是一个有效的工作解决方案,但您的回答不适用于此问题。
    猜你喜欢
    • 1970-01-01
    • 2020-08-30
    • 1970-01-01
    • 2020-10-15
    • 2020-10-04
    • 2021-07-13
    • 2023-02-25
    • 2020-09-05
    • 2021-07-06
    相关资源
    最近更新 更多