【问题标题】:How can I deafen a discord bot?我怎样才能使不和谐的机器人耳聋?
【发布时间】:2020-12-14 04:21:30
【问题描述】:

我希望我的音乐机器人在加入频道时耳聋。但我仍然希望它播放音乐。我已经尝试过使用 await change_voice_state(*, channel, self_mute=False, self_deaf=False) 函数和 discord.py 文档,但没有任何帮助。我使用commands.command 方法。这是我的源代码的相关部分:

    async def play(self, ctx, *, url):
        """Plays a song from a URL"""

        client = ctx.guild.voice_client
        state = self.get_state(ctx.guild)  # get the guild's state

        send_message = state.now_playing is not None

        # connect to author's voice channel
        if not client:
            if ctx.author.voice is None:
                raise commands.CommandError("You have to be in a voice channel.")
            else:
                channel = ctx.author.voice.channel
                client = await channel.connect()

await channel.connect 似乎是相关部分。我希望我能在这里得到帮助。

我已经看到了其他可以使用的文档:

await voice_client.main_ws.voice_state(ctx.guild.id, channel.id, self_deaf=True)

但我收到以下错误消息:AttributeError: 'VoiceClient' object has no attribute 'main_ws'

我的代码如下所示:

        if not client:
            if ctx.author.voice is None:
                raise commands.CommandError("Du musst in einem Sprachkanal sein, um dies zu tun.")
            else:
                channel = ctx.author.voice.channel

                client = await channel.connect()
                voice_client = ctx.guild.voice_client
                channel = voice_client.channel
                await voice_client.main_ws.voice_state(ctx.guild.id, channel.id, self_deaf=True)

也许我在某个地方犯了错误?

【问题讨论】:

  • @Sneftel 我看过这个。我几乎尝试了这里也写的所有内容。但是这是我所做的:client = await channel.connect() , voice_client = ctx.guild.voice_client channel = voice_client.channel - await voice_client.main_ws.voice_state(ctx.guild.id, channel.id, self_deaf=True) 这给了我以下错误:AttributeError: 'VoiceClient' object has no attribute 'main_ws' 所以我必须将其更改为 guild 吗?

标签: discord discord.py


【解决方案1】:

在您的情况下,您可以尝试使用以下内容:

await ctx.guild.change_voice_state(channel=channel, self_deaf=True)

我还建议添加 self_mute 并将其设置为 True,以确保机器人正在播放您想要的音乐。

总结起来就是你可以试试的代码:

await ctx.guild.change_voice_state(channel=channel, self_mute=False, self_deaf=True)

【讨论】:

    猜你喜欢
    • 2021-07-24
    • 2022-11-11
    • 2021-07-09
    • 2020-04-15
    • 2019-06-14
    • 2018-04-18
    • 2021-03-07
    • 1970-01-01
    • 2021-04-06
    相关资源
    最近更新 更多