Discord 机器人命令列表
Discord bot command list
我有一个 discord 机器人的命令列表,所以我可以稍后更改或修改它们。当有人在 discord 中编写命令时,我会尝试检查它是否在命令列表中。问题是我收到错误:
for message.content.startswith in commands:
AttributeError: 'str' object attribute 'startswith' is read-only
有办法吗?我怎样才能让它不是只读的...或者我该如何解决这个问题?
代码:
import discord, asyncio
client = discord.Client()
@client.event
async def on_ready():
print('logged in as: ', client.user.name, ' - ', client.user.id)
@client.event
async def on_message(message):
commands = ('!test', '!test1', '!test2')
for message.content.startswith in commands:
print('true')
if __name__ == '__main__':
client.run('token')
这部分是问题:
for message.content.startswith in commands:
print('true')
这没有任何意义。我假设 message.content
是一个字符串。 startswith
是一个字符串方法,但它需要一个参数,see here。您需要传递 startswith
您正在搜索的实际字符。例如,"hello".startswith("he")
将 return 为真。我相信这就是你想要的:
for command in commands:
if message.content.startswith(command):
print('true')
我有一个 discord 机器人的命令列表,所以我可以稍后更改或修改它们。当有人在 discord 中编写命令时,我会尝试检查它是否在命令列表中。问题是我收到错误:
for message.content.startswith in commands:
AttributeError: 'str' object attribute 'startswith' is read-only
有办法吗?我怎样才能让它不是只读的...或者我该如何解决这个问题?
代码:
import discord, asyncio
client = discord.Client()
@client.event
async def on_ready():
print('logged in as: ', client.user.name, ' - ', client.user.id)
@client.event
async def on_message(message):
commands = ('!test', '!test1', '!test2')
for message.content.startswith in commands:
print('true')
if __name__ == '__main__':
client.run('token')
这部分是问题:
for message.content.startswith in commands:
print('true')
这没有任何意义。我假设 message.content
是一个字符串。 startswith
是一个字符串方法,但它需要一个参数,see here。您需要传递 startswith
您正在搜索的实际字符。例如,"hello".startswith("he")
将 return 为真。我相信这就是你想要的:
for command in commands:
if message.content.startswith(command):
print('true')