discord.py模块如何删除命令文本?

时间:2017-05-14 11:30:48

标签: python-3.x discord.py

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的部分工作:

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

最好的方法是什么?提前谢谢。

1 个答案:

答案 0 :(得分:0)

对不起你26天没找到答案了。如果您仍在寻找答案,我希望我能提供一些帮助。所以我运行你的代码,机器人运行命令,我的消息被删除,然后机器人的消息也被删除。解决此问题的一种方法是提供 if 语句,这意味着如果作者一个机器人,机器人只会删除该消息。

$(document).ready(function(){
$("#text").keypress(function(event) {   
   if (event.which == 13) { 
      var s = $(this).val();
      $(this).val(s+"\n");  //\t for tab
   }
});      
});

另一种仅删除命令消息的方法是使用另一个 if 语句。以下代码是特定的,因此您只删除命令,而不仅仅是所有用户的消息(如果它们不是机器人)。以下代码使用@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) 将消息作为字符串返回。

message.content
相关问题