Discord.py禁止命令
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Discord.py禁止命令相关的知识,希望对你有一定的参考价值。
if message.content.upper().startswith('!BAN'):
if "449706643710541824" in [role.id for role in message.author.roles]:
await
我有基本设置,所以只有管理员可以禁止。我想制作禁令命令,但我不知道该怎么做。
答案
我建议使用discord.ext.commands
来制作命令,它更容易使用。禁止的功能是discord.Client.ban(member, delete_message_days = 1)
。这是使用discord.ext.commands
的示例:
bot = commands.Bot(command_prefix = "!")
@bot.command(pass_context = True)
async def ban(member: discord.Member, days: int = 1):
if "449706643710541824" in [role.id for role in message.author.roles]:
await bot.ban(member, days)
else:
await bot.say("You don't have permission to use this command.")
bot.run("<TOKEN>")
另一答案
我为我的机器人获得的禁令命令显然是不保留禁止部分的注释,我只是把它放在那里当我不知道如何将其锁定到角色
#bans a user with a reason
@client.command()
@commands.has_any_role("Keyblade Master","Foretellers")
async def ban (ctx, member:discord.User=None, reason =None):
if member == None or member == ctx.message.author:
await ctx.channel.send("You cannot ban yourself")
return
if reason == None:
reason = "For being a jerk!"
message = f"You have been banned from {ctx.guild.name} for {reason}"
await member.send(message)
# await ctx.guild.ban(member)
await ctx.channel.send(f"{member} is banned!")
以上是关于Discord.py禁止命令的主要内容,如果未能解决你的问题,请参考以下文章