qwi*_*qwi -2 python-3.x discord
我有一个不和谐机器人的命令列表,所以我可以稍后更改或修改它们。当有人不和谐地编写命令时,我试图检查它是否在命令列表中。问题是我收到错误:
for message.content.startswith in commands:
AttributeError: 'str' object attribute 'startswith' is read-only
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点?我如何使它不是只读的……或者我将如何解决这个问题?
编码:
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')
Run Code Online (Sandbox Code Playgroud)
这部分是问题:
for message.content.startswith in commands:
print('true')
Run Code Online (Sandbox Code Playgroud)
这没有任何意义。我假设message.content是一个字符串。startswith是一个字符串方法,但它需要一个参数,请参见此处。您需要传递startswith您正在搜索的实际字符。例如,"hello".startswith("he")将返回true。我相信这就是你想要的:
for command in commands:
if message.content.startswith(command):
print('true')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1254 次 |
| 最近记录: |