因此,我想为我的discord服务器创建一个bot,以便它加入我当前所在的一个语音频道,并根据命令对所有成员进行静音和取消静音,如vcmute
和vcunmute
,但缺少一些内容,并且没有任何工作。这是我写的代码
import discord
from discord.ext import commands
import os
client = discord.Client()
DISCORD_TOKEN = os.getenv("myToken")
bot = commands.Bot(command_prefix="$")
@client.event
async def on_ready():
print('BOT ACTIVATED')
@bot.command()
async def join(ctx):
channel = ctx.message.author.voice.channel
await channel.connect()
@bot.command()
async def vcmute(ctx):
vc = ctx.author.voice.channel
for member in vc.members:
await member.edit(mute=True)
@bot.command()
async def vcunmute(ctx):
vc = ctx.author.voice.channel
for member in vc.members:
await member.edit(mute=False)
bot.run("myToken")
代码对我来说是有效的,bot可能缺少管理员权限,这会阻止它对成员进行静音和取消静音
您还可以添加^{} 装饰器,让它检查管理员权限,例如您的代码:
相关问题 更多 >
编程相关推荐