【发布时间】:2021-01-10 08:32:31
【问题描述】:
我正在尝试制作一个 Discord 机器人,使用语音聊天将参与者的声音静音。
为此,我正在使用 Python。
这是我的代码,但它没有按预期工作。
import discord
from discord.ext import commands
client = commands.Bot(command_prefix=" !")
@client.event
async def on_ready():
print('BOT ACTIVATED')
@client.command()
async def mute(ctx):
voice_client = ctx.guild.voice_client
if not voice_client:
return
channel = voice_client.channel
await voice_client.voice_state(ctx.guild.id, channel.id, self_mute=True)
client.run(My Token)
我的想法是:
我将输入的命令:!muteall\
机器人会将语音聊天中的所有参与者静音
我将输入的命令:!unmuteall\
机器人会取消语音聊天中所有参与者的静音。
【问题讨论】:
-
你能显示你的整个代码文件,减去令牌吗?你有
@client.command()上面的装饰器async def mute吗?main_ws应该在voice_client.main_ws.voice_state()中是什么?我在 discord.py 文档中找不到它 -
import discord from discord.ext import commands client = commands.Bot(command_prefix=" !") @client.event async def on_ready(): print('BOT ACTIVATED') @client.command() async def mute(ctx): voice_client = ctx.guild.voice_client if not voice_client: return channel = voice_client.channel await voice_client.voice_state(ctx.guild.id, channel.id, self_mute=True) client.run(My Token)