2017-12-25 28 views
-2

불화 봇에 대한 명령 목록이 있으므로 나중에 변경하거나 수정할 수 있습니다. 누군가가 불화에 명령을 쓸 때 명령 목록에 있는지 확인하고 보려고합니다. 문제는 내가 오류가 발생했습니다 :불화 봇 명령 목록

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') 
+0

'discord.py'에 대한 명령 확장을보아야한다. 그 문서는 거의 존재하지 않지만 [예제 로봇] (https://github.com/Rapptz/discord.py/blob/master/examples/basic_bot.py)이 있습니다. –

답변

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')