【发布时间】:2018-07-21 22:22:00
【问题描述】:
我最近有了 DMing 我的机器人命令的想法。例如,一个命令可以让我从该机器人所在的每个服务器中解禁。
不幸的是,我没有任何命令的起点,因为我什至不确定 DMing 命令是否可行。
discord.py、command 或 DM 等关键字在 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))
【问题讨论】:
-
您尚未发布任何当前代码。您希望如何获得帮助。根据您编写机器人的方式,接受 dms 作为命令会有所不同。
-
确实如此。对于那个很抱歉。我会尽快从我的机器人中添加一些示例代码。
标签: python discord discord.py