只说命令机器人所有者

时间:2018-05-24 12:36:58

标签: discord.py

我正在努力使我的!say命令仅适用于机器人所有者。这就是我目前所拥有的

@bot.command(pass_context = True)
async def say(ctx, *args):
    mesg = ' '.join(args)
    await bot.delete_message(ctx.message)
    return await bot.say(mesg)

代码可以工作,但我想这样做只有我(机器人所有者)可以运行命令。

4 个答案:

答案 0 :(得分:3)

您还可以使用装饰器@is_owner()

@bot.command(pass_context = True)
@commands.is_owner()
async def say(ctx):
    your code...

答案 1 :(得分:1)

尝试通过添加if语句

这样做
@bot.command(pass_context=True)
async def say(ctx):
      if ctx.message.author.id =='bot owner id':
      then execute the following code

答案 2 :(得分:1)

我就是这样做的 - 如果这不能按预期工作,请发表评论。

@client.command()
@commands.is_owner() 
async def say(ctx, *, message):
   ctx.send(f"{message}")

祝您编码愉快!抱歉回复晚了,我正在阅读旧问题并寻求未解决的问题

(重制)

答案 3 :(得分:0)

1.0文档中check的文档具有以下示例(略有修改。)

def user_is_me(ctx):
    return ctx.message.author.id == "Your ID" 

@bot.command(pass_context = True)
@commands.check(user_is_me)
async def say(ctx, *args):
    mesg = ' '.join(args)
    await bot.delete_message(ctx.message)
    return await bot.say(mesg)

How to find your ID

相关问题