【发布时间】:2019-04-23 08:08:57
【问题描述】:
我的python脚本:
import discord
TOKEN = 'X'
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!test'):
msg = "This message is a test".format(message)
await client.send_message(message.channel, msg)
if message.content.startswith('!admin'):
msg = "This command can be executed only as the owner".format(message)
await client.send_message(message.channel, msg)
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(TOKEN)
对于我的 discord 机器人,我想这样做,以便每个人都可以使用 !test,并且机器人会以“此消息是测试”作为响应。另外,我希望 !admin 只能由所有者角色执行,机器人只会回复“此命令只能作为所有者执行”,否则它会回复“对不起,您没有使用此命令的权限”命令”。我怎样才能做到这一点?
【问题讨论】:
-
对于所有者角色你了解多少?它的 id、它的名字等......
-
让我改写一下,而不是使用所有者角色,我将如何使命令只有在用户具有角色“成员”时才能执行?
标签: python python-3.x bots discord.py