Python 如何阻止特定角色在discord.py中发言?
所以,现在我想让一个特定的角色不能在频道里讲话。我有可以工作的代码,但只限制Python 如何阻止特定角色在discord.py中发言?,python,discord.py,Python,Discord.py,所以,现在我想让一个特定的角色不能在频道里讲话。我有可以工作的代码,但只限制ctx.guild.default\u角色(@everybody)说话 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_read
ctx.guild.default\u角色(@everybody)说话
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角色仍然可以在那个频道说话
谢谢大家:)使用和如下:
await ctx.channel.set_permissions(discord.utils.get(ctx.guild.members, name='Foo'), send_messages=False)
discord.utils.get(ctx.guild.members,name='Foo')
按名称获取discord角色