获取与discord.py
问题描述:
我试图让用户的角色来执行的命令的作用:获取与discord.py
async def clear (ctx, n):
if "Mod" in [y.name.lower() for y in ctx.message.author.roles]:
//delete messages
else:
client.send_message(ctx.message.channel, "You are not allowed to use this command!")
当一个正常的用户使用!clear
,他可以清除消息,但也得到了权限错误。
代码:
@bot.command(pass_context=True)
async def clear(ctx, n):
if "mod" in [y.name.lower() for y in ctx.message.author.roles]:
n = int(n)
tn = n + 1
async for x in bot.logs_from(ctx.message.channel, limit=tn):
await bot.delete_messages(x)
await bot.send_message(ctx.message.channel, "Deleted" + str(n) + "messages")
elif not "mod" in [y.name.lower() for y in ctx.message.author.roles]:
await bot.send_message(ctx.message.channel, "You need the **Mod** role to use this command!")
当一个正常的用户使用!clear
,他可以清除消息,但也得到了权限错误。
SOLUTION:
@bot.command(pass_context=True)
async def clear(ctx, n):
if "mod" in [y.name.lower() for y in ctx.message.author.roles]:
n = int(n)
msg = []
tn = n + 1
async for x in bot.logs_from(ctx.message.channel, limit=tn):
msg.append(x)
await bot.delete_messages(x)
await bot.send_message(ctx.message.channel, "Deleted" + str(n) + "messages")
elif not "mod" in [y.name.lower() for y in ctx.message.author.roles]:
await bot.send_message(ctx.message.channel, "You need the **Mod** role to use this command!")
如何用大写字母“Mod”匹配'name.lower()'?我会很惊讶,如果删除邮件*有史以来*真的跑... – squaswin
它发生与“国防部”相同的事情@squaswin – Francesco
你可以请编辑您的帖子的整个功能,这个问题是一个代码以外的产品你已经发送。如果一个普通用户收到错误消息*和*可以删除这些消息,这意味着删除的呼叫实际上并没有在该区域内... – squaswin