2017-12-25 7 views
-2

私はディスボイスボットのコマンドリストを持っているので、後で変更または変更できます。誰かが不和にコマンドを書くと、コマンドリストにそのコマンドがあるかどうかを確認しようとしています。問題は、エラーが表示されることです。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') 
+0

あなたは 'discord.py'ためのコマンド拡張をご覧ください:私はこれが何をしたいと考えています。そのドキュメントはほとんど存在しませんが、[example bot](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') 
関連する問題