所以我写了一个批量消息删除的代码,但是我希望只有管理员能够使用这个命令。
import discord
import asyncio
from discord.ext.commands import Bot
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
await client.change_presence(activity=discord.Game('NLRP with MaximaVoid'))
async def on_message(self, message):
# bulk deletion command
if message.content.startswith('!ldlmsg'):
await message.channel.purge()
if message.content.startswith('!bdelmsg50'):
delnum = 50
await message.channel.purge(limit = delnum)
if message.content.startswith('!bdelmsg10'):
delnum = 10
await message.channel.purge(limit = delnum)
发布于 2021-01-13 20:28:21
您可以使用以下装饰器:
@commands.is_owner() # If you only want the owner to execute this command
如果有一个名为Admin
或Administrator
或类似的角色:
@commands.has_role('Admin') # Anyone who executes the command must have the 'Admin' role to continue
如果您希望具有任何指定角色的用户能够执行该命令:
@commands.has_any_role('Admin', 'Administrator') # You can add as many roles as you want
最后,如果您只希望拥有'Administrator‘权限的用户能够执行此命令:
@commands.has_permissions(administrator=True, ban_members=True) # You can add as many permissions as you would like
https://stackoverflow.com/questions/65697173
复制相似问题