如何获取机器人的语音状态?

时间:2020-12-21 19:33:31

标签: python discord discord.py

我想创建一个可以自己静音和取消静音的 discord.py 机器人。但我不知道如何获取机器人的 VoiceState。

import discord, asyncio
from discord.ext import commands

bot = commands.Bot(command_prefix="/")

@bot.command()
async def unmute(ctx):
    voice_client=ctx.guild.voice_client
    channel=voice_client.channel
    if ???ctx.channel.guild.voice_state???(channel=channel, self_deaf=True):
        await ctx.channel.guild.change_voice_state(channel=channel, self_deaf=False)
        await ctx.send("Unmuted!")
        return
    else:
        await ctx.send("Error! Not muted!")
        return

1 个答案:

答案 0 :(得分:0)

您需要启用 intents.voice_states

intents = discord.Intents.default() # enabling everything apart from privileged intents (members and presences)

bot = commands.Bot(command_prefix='/', intents=intents)

reference

另外,它不是 ctx.channel.guild.voice_state(...),而是 ctx.guild.voice_clientctx.voice_client