我想创建一个可以自己静音和取消静音的 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
答案 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)
另外,它不是 ctx.channel.guild.voice_state(...)
,而是 ctx.guild.voice_client
或 ctx.voice_client