【问题标题】:How to only let certain users use a command discord.py rewrite如何只让某些用户使用命令 discord.py rewrite
【发布时间】:2021-04-23 09:18:27
【问题描述】:

我正在处理 discord.py rewrite 中的机器人,想知道如何只让我使用 .dm 命令来防止其他人冒充机器人,我当前的代码是:

@client.command()
async def dm(ctx, users: Greedy[User], *, message):
    if message.author.id == "751537000036696128":
      for user in users:
        await user.send(message)
        await ctx.send("Success!")

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    方法一:

    所有者只能使用@commands.is_owner() Reference

    @client.command()
    @commands.is_owner()
    async def dm(ctx, users: Greedy[User], *, message):
    

    方法二:

    检查某些属性Reference

    def admin_or_testserver(ctx):
        return ctx.author.guild_permissions.administrator or ctx.guild.id == 123456 or ctx.channel != discord.DMChannel
    
    @bot.command()
    @commands.check(admin_or_testserver)
    async def dm(ctx, users: Greedy[User], *, message):
    

    【讨论】:

      【解决方案2】:

      添加 @commands.is_owner() 装饰器

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-09-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-10
        • 2020-10-26
        • 1970-01-01
        相关资源
        最近更新 更多