Discord.py禁止命令

问题描述 投票:0回答:2
    if message.content.upper().startswith('!BAN'):
        if "449706643710541824" in [role.id for role in message.author.roles]:
            await

我有基本设置,所以只有管理员可以禁止。我想制作禁令命令,但我不知道该怎么做。

python discord.py
2个回答
1
投票

我建议使用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>")

0
投票

我为我的机器人获得的禁令命令显然是不保留禁止部分的注释,我只是把它放在那里当我不知道如何将其锁定到角色

#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!")
© www.soinside.com 2019 - 2024. All rights reserved.