首页 文章

DM命令来扰乱机器人

提问于
浏览
0

我最近想到了DMing我的机器人命令 . 例如,一个命令可以从机器人所在的每个服务器上取消我 .

不幸的是,我没有任何命令的起点,因为我甚至不确定DMing命令是否可行 .

discord.pycommandDM 这样的关键字在google中非常常见,因此找到有关该主题的任何有用信息非常困难 .

我正在寻找机器人接收DM作为命令的方式,并且只接受来自我的方式(如果有人想共享任何代码,我的ID存储在变量 ownerID 中) .

虽然我主要是在寻找上述内容,但DM unban 命令的一些代码也非常有用 .

编辑:我被要求显示我的机器人的一些示例代码 . 以下是命令 number 的代码,它生成一个随机数并将其发送到消息中 . 我希望这可以让您了解我的机器人是如何制作的:

@BSL.command(pass_context = True)
async def number(ctx, minInt, maxInt):
    if ctx.message.author.server_permissions.send_messages or ctx.message.author.id == ownerID:
        maxInt = int(maxInt)
        minInt = int(minInt)
        randomInt = random.randint(minInt, maxInt)
        randomInt = str(randomInt)
        await BSL.send_message(ctx.message.channel, 'Your random number is: ' + randomInt)
    else:
        await BSL.send_message(ctx.message.channel, 'Sorry, you do not have the permissions to do that @{}!'.format(ctx.message.author))

1 回答

  • 1

    您可以在私人消息中发送命令 . 就像是

    @BSL.command(pass_context=True)
    async def unban(ctx):
        if ctx.message.channel.is_private and ctx.message.author.id == ownerID:
            owner = await BSL.get_user_info(ownerID)
            await BSL.say('Ok {}, unbanning you.'.format(owner.name))
            for server in BSL.servers:
                try:
                    await BSL.unban(server, owner) # I think having the same name should be fine.  If you see weird errors this may be why.
                    await BSL.say('Unbanned from {}'.format(server.name))
                except discord.HTTPException as e:
                    await BSL.say('Unbanning failed in {} because\n{}'.format(server.name, e.text))
                except discord.Forbidden:
                    await BSL.say('Forbidden to unban in {}'.format(server.name))
        else:
            if ctx.message.author.id != ownerID:
                await BSL.say('You are not my owner')
            if not ctx.message.channel.is_private:
                await BSL.say('This is a public channel')
    

    应该管用 . 我不确定如果你试图解雇一个没有被禁止的用户会发生什么,这可能是什么引起了 HTTPException

相关问题