2017-05-14 4 views
0
from discord.ext.commands import Bot 

import secrets 
from time import sleep 

discordBot = Bot(command_prefix = ".") 

listStrings = ['add a reaction', 'adnd'] 

@discordBot.event 
async def on_read(): 
    print('Client logged in') 


@discordBot.command() 
async def s(*args): 
     return await discordBot.say (" ".join(args)) 

@discordBot.command() 
async def close(): 
    quit() 


discordBot.run(secrets.token) 

私は「.s(テキスト)」と言っていましたが、ボットはテキストを(すでに動作していますが)削除していますが、どうすればいいですか?私はon_messageの作業をしました:discord.py module後でコマンドテキストを削除するにはどうしたらいいですか?

@discordbot.event 
async def on_message(message): 
    await discordBot.delete_message(message) 

これを行うにはどうすればよい方法がありますか?前もって感謝します。

答えて

0

申し訳ありませんが、26日間回答がありません。あなたはまだ答えを探しているなら、私はいくつかの助けを提供できることを願っています。だから私はあなたのコードを実行し、ボットはコマンドを実行し、私のメッセージは削除され、ボットのメッセージも削除されました。これを解決する1つの方法は、ステートメントの場合です。つまり、作成者がではない場合は、 botです。

@test_bot.event 
async def on_message(message): 
    if not (message.author).bot: 
     await test_bot.delete_message(message) 
    await test_bot.process_commands(message) 

コマンドであるメッセージのみを削除する別の方法は、別の if文を使用することです。次のコードは特定のものなので、ボットでない場合はすべてのユーザーのメッセージだけでなく、コマンドを削除するだけです。次のコードは、メッセージを文字列として返すmessage.contentを使用します。

@test_bot.event 
async def on_message(message): 
    if message.content.startswith('.s'): 
     await test_bot.delete_message(message) 
    await test_bot.process_commands(message) 
関連する問題