我如何才能阻止特定角色用不和谐的.py说话



所以,现在我正试图让一个特定的角色不能在频道中说话。我有一些代码可以工作,但只限制ctx.guild.default_role(@everyone(说话。

import discord
import os
from discord.ext import commands
from keep_alive import keep_alive
import asyncio
bot = commands.Bot(command_prefix='+')
@bot.event
async def on_ready():
print(f'''We have logged in as {bot.user.name}''')

@bot.command()
@commands.guild_only()
@commands.has_guild_permissions(manage_channels=True)
@commands.bot_has_guild_permissions(manage_channels=True)
async def lock(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=False)
await ctx.send('**An admin/moderator has locked this channel. Please wait for an admin to unlock this channel with `+unlock`.**')
print(f'{ctx.author} locked channel {ctx.channel}')
@bot.command()
@commands.guild_only()
@commands.has_guild_permissions(manage_channels=True)
@commands.bot_has_guild_permissions(manage_channels=True)
async def unlock(ctx):
await ctx.channel.set_permissions(ctx.guild.default_role, send_messages=True)
await ctx.send('**An admin/moderator has unlocked this channel with `unlock`.**')
print(f'{ctx.author} unlocked channel {ctx.channel}.')
keep_alive()
bot.run(os.getenv('TOKEN'))

有人能帮帮我吗?

重申的问题:我需要一个像";农民角色;不能说话,当管理员说话时,@everyone角色仍然可以在该频道中说话。

感谢大家:(

使用TextChannel.set_permissions和discord.utils.get如下:

await ctx.channel.set_permissions(discord.utils.get(ctx.guild.members, name='Foo'), send_messages=False)

discord.utils.get(ctx.guild.members, name='Foo')通过名称获得不协调角色。

最新更新