如何使漫游器删除xx消息。示例!clear xx
和!clear xx @user
If i use `!clear xx` it should delete xx message.
If i use `!clear xx @user` it should delete xx message of User tagged.
答案 0 :(得分:1)
以this answer作为起点:
from discord.ext.commands import has_permissions
from datetime import datetime
@bot.command(pass_context=True)
@has_permissions(administrator=True) # Like the properties of a Permissions object
async def censor(ctx, limit: int, target: discord.User = None):
check = (lambda message: message.author.id == target.id) if target else None
try:
await bot.purge_from(ctx.message.channel,
check=check,
limit=limit)
except discord.Forbidden:
await bot.say("I don't have permission to do that")
@censor.error
async def censor_error(error, ctx):
if isinstance(error, commands.CheckFailure):
await bot.send_message(ctx.message.channel, "You don't have permissions")
请注意,purge_from
需要一个机器人帐户。