首页 文章

Discord bot命令列表

提问于
浏览
-2

我有一个discord bot的命令列表,所以我可以稍后更改或修改它们 . 当有人在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')

1 回答

  • 4

    这部分是问题:

    for message.content.startswith in commands:
        print('true')
    

    这没有任何意义 . 我假设 message.content 是一个字符串 . startswith 是一个字符串方法,但需要一个参数see here . 您需要传递 startswith 您正在搜索的实际字符 . 例如, "hello".startswith("he") 将返回true . 我相信这就是你想要的:

    for command in commands:
        if message.content.startswith(command):
            print('true')
    

相关问题