[英]Discord bot won't mute all people
It only mutes me and itself when it shouldn't, bot has highest role and also has permission in joined voice channel.它只会在不应该的时候让我和它自己静音,机器人具有最高的角色,并且在加入的语音频道中也有权限。 any ideas?有任何想法吗?
@bot.command()
async def mute(ctx):
voice_client = ctx.guild.voice_client #
if not voice_client:
return
channel = voice_client.channel
people = channel.members
for person in people:
if person == client.user:
continue
await person.edit(mute=True, reason="{} told me to mute everyone in this channel".format(ctx.author))
edit Full code:编辑完整代码:
import discord
from discord.ext import commands
import os
from discord.utils import get
client = discord.Client()
DISCORD_TOKEN = os.getenv("TokenGoesHere")
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 disconnect(ctx):
channel = ctx.message.author.voice.channel
await channel.disconnect()
@bot.command()
@commands.has_permissions(administrator=True)
async def mute(ctx):
voice_client = ctx.guild.voice_client #get bot's current voice connection in this guild
if not voice_client: #if no connection...
return #probably should add some kind of message for the users to know why nothing is happening here, like ctx.send("I'm not in any voice channel...")
channel = voice_client.channel #get the voice channel of the voice connection
people = channel.members #get the members in the channel
for person in people: #loop over those members
if person == client.user: #if the person being checked is the bot...
continue #skip this iteration, to avoid muting the bot
await person.edit(mute=True, reason="{} told me to mute everyone in this channel".format(ctx.author))
#edit the person to be muted, with a reason that shows in the audit log who invoked this command. Line is awaited because it involves sending commands ("mute this user") to the server then waiting for a response.
@bot.command()
@commands.has_permissions(administrator=True)
async def unmute(ctx):
voice_client = ctx.guild.voice_client
if not voice_client:
return
channel = voice_client.channel
people = channel.members
for person in people:
if person == client.user:
continue
await person.edit(mute=False, reason="{} told me to mute everyone in this channel".format(ctx.author))
bot.run("TokenGoesHere")
Hope this helps, Bot sometimes mutes only itself or only itself and other user, but specifically that one user... It only mutes me and itself when it shouldn't, bot has highest role and also has permission in joined voice channel.希望这会有所帮助,Bot 有时只会静音自己或仅静音自己和其他用户,但特别是那个用户......它只会在不应该静音的时候静音我和自己,bot 具有最高角色,并且在加入的语音频道中也有权限。 any ideas?有任何想法吗?
You have to define the intents to use some events, functions like on_message
, guild.members
, channel.members
etc.您必须定义使用某些事件的意图,如on_message
、 guild.members
、 channel.members
等函数。
# Here is your imports
import discord
intents = discord.Intents().all()
bot = commands.Bot(command_prefix='', intents=intents)
# Rest of your code
Also, you have to activate intents from Discord Developer Portal .此外,您必须从Discord Developer Portal激活意图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.