更改
@client.command(name="whoami",description="who are you?")async def whoami():
至
@client.command(pass_context=True)async def whoami(ctx):
然后,您可以
ctx用来获取各种内容,例如编写它的用户,消息内容等等。
要查看a
User是否为管理员
ifctx.message.author.server_permissions.administrator:,
True如果用户为administrator则应返回
您的代码应如下所示:
import discordimport asynciofrom discord.ext.commands import Botclient = Bot(description="My Cool Bot", command_prefix="!", pm_help = False, )@client.eventasync 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')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)