Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何阻止特定角色在discord.py中发言?_Python_Discord.py - Fatal编程技术网

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角色