【发布时间】:2021-05-10 01:08:30
【问题描述】:
所以,现在我正在尝试让特定角色无法在频道中讲话。我有有效的代码,但只限制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 角色仍然可以在该频道中说话。
谢谢大家:)
【问题讨论】:
标签: python discord.py