<small id='ihiL1'></small><noframes id='ihiL1'>

      <bdo id='ihiL1'></bdo><ul id='ihiL1'></ul>
    <i id='ihiL1'><tr id='ihiL1'><dt id='ihiL1'><q id='ihiL1'><span id='ihiL1'><b id='ihiL1'><form id='ihiL1'><ins id='ihiL1'></ins><ul id='ihiL1'></ul><sub id='ihiL1'></sub></form><legend id='ihiL1'></legend><bdo id='ihiL1'><pre id='ihiL1'><center id='ihiL1'></center></pre></bdo></b><th id='ihiL1'></th></span></q></dt></tr></i><div id='ihiL1'><tfoot id='ihiL1'></tfoot><dl id='ihiL1'><fieldset id='ihiL1'></fieldset></dl></div>

    <tfoot id='ihiL1'></tfoot>

  1. <legend id='ihiL1'><style id='ihiL1'><dir id='ihiL1'><q id='ihiL1'></q></dir></style></legend>

    1. Discord bot 检查用户是否为管理员

      时间:2023-09-09

      <small id='pBphQ'></small><noframes id='pBphQ'>

      <legend id='pBphQ'><style id='pBphQ'><dir id='pBphQ'><q id='pBphQ'></q></dir></style></legend>

        <tbody id='pBphQ'></tbody>
        <i id='pBphQ'><tr id='pBphQ'><dt id='pBphQ'><q id='pBphQ'><span id='pBphQ'><b id='pBphQ'><form id='pBphQ'><ins id='pBphQ'></ins><ul id='pBphQ'></ul><sub id='pBphQ'></sub></form><legend id='pBphQ'></legend><bdo id='pBphQ'><pre id='pBphQ'><center id='pBphQ'></center></pre></bdo></b><th id='pBphQ'></th></span></q></dt></tr></i><div id='pBphQ'><tfoot id='pBphQ'></tfoot><dl id='pBphQ'><fieldset id='pBphQ'></fieldset></dl></div>

              <bdo id='pBphQ'></bdo><ul id='pBphQ'></ul>
              1. <tfoot id='pBphQ'></tfoot>
                本文介绍了Discord bot 检查用户是否为管理员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                您好,我是不和谐的 python 编码新手,我试图创建一个命令来告诉用户他们是否是管理员,但是很好......它一点也不工作

                Hi i'm new to python coding with discord and I have tried to make a command that tells the user if they are a admin or not but well... its not working in the slightest

                    @client.command(name="whoami",description="who are you?")
                async def whoami():
                    if message.author == client.user:
                        return
                    if context.message.author.mention == discord.Permissions.administrator:
                        msg = "You're an admin {0.author.mention}".format(message)  
                        await client.send_message(message.channel, msg)
                    else:
                        msg = "You're an average joe {0.author.mention}".format(message)  
                        await client.send_message(message.channel, msg)
                

                然后当我尝试输入 whoami 时得到这个

                I then get this when I try to type whoami

                Ignoring exception in command whoami
                Traceback (most recent call last):
                  File "/home/python/.local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 50, in wrapped
                    ret = yield from coro(*args, **kwargs)
                  File "<stdin>", line 3, in whoami
                NameError: name 'message' is not defined
                
                The above exception was the direct cause of the following exception:
                
                Traceback (most recent call last):
                  File "/home/python/.local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 846, in process_commands
                    yield from command.invoke(ctx)
                  File "/home/python/.local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 374, in invoke
                    yield from injected(*ctx.args, **ctx.kwargs)
                  File "/home/python/.local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 54, in wrapped
                    raise CommandInvokeError(e) from e
                discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'message' is not defined
                

                推荐答案

                改变

                @client.command(name="whoami",description="who are you?")
                async def whoami():
                

                @client.command(pass_context=True)
                async def whoami(ctx):
                

                然后你可以使用ctx来获取各种东西,比如写它的用户,消息内容等等

                Then you can use ctx to get all kinds of stuff like the user that wrote it, the message contents and so on

                要查看 User 是否是管理员,请执行以下操作
                if ctx.message.author.server_permissions.administrator: 如果用户是管理员,则应该返回 True

                To see if a User is an administrator do
                if ctx.message.author.server_permissions.administrator: which should return True if the user is an an Administator

                您的代码应如下所示:

                import discord
                import asyncio
                from discord.ext.commands import Bot
                
                client = Bot(description="My Cool Bot", command_prefix="!", pm_help = False, )
                @client.event
                async def on_ready():
                  print("Bot is ready!")
                  return await client.change_presence(game=discord.Game(name='My bot'))
                
                @client.command(pass_context = True)
                async def whoami(ctx):
                    if ctx.message.author.server_permissions.administrator:
                        msg = "You're an admin {0.author.mention}".format(ctx.message)  
                        await client.send_message(ctx.message.channel, msg)
                    else:
                        msg = "You're an average joe {0.author.mention}".format(ctx.message)  
                        await client.send_message(ctx.message.channel, msg)
                client.run('Your_Bot_Token')
                

                这篇关于Discord bot 检查用户是否为管理员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:如何将函数绑定到 Qt 菜单栏中的操作? 下一篇:discord.py 中 on_message 的冷却时间

                相关文章

                最新文章

                • <bdo id='qiItg'></bdo><ul id='qiItg'></ul>

                <small id='qiItg'></small><noframes id='qiItg'>

                <legend id='qiItg'><style id='qiItg'><dir id='qiItg'><q id='qiItg'></q></dir></style></legend>
                  1. <tfoot id='qiItg'></tfoot>
                    <i id='qiItg'><tr id='qiItg'><dt id='qiItg'><q id='qiItg'><span id='qiItg'><b id='qiItg'><form id='qiItg'><ins id='qiItg'></ins><ul id='qiItg'></ul><sub id='qiItg'></sub></form><legend id='qiItg'></legend><bdo id='qiItg'><pre id='qiItg'><center id='qiItg'></center></pre></bdo></b><th id='qiItg'></th></span></q></dt></tr></i><div id='qiItg'><tfoot id='qiItg'></tfoot><dl id='qiItg'><fieldset id='qiItg'></fieldset></dl></div>