discord.py执行命令后删除作者消息 [英] discord.py delete author message after executing command

查看:132
本文介绍了discord.py执行命令后删除作者消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要机器人从命令作者处删除消息,并留下机器人消息。任何帮助将不胜感激!谢谢。

I need the bot to delete the message from the command author, and leave the bot message. Any help will be appreciated! thank you.

我已经尝试在Google上寻找答案,但是没有任何作用

I have already tried looking for a answer on google but nothing has worked

推荐答案

您可以通过使用 pass_context 选项将上下文传递给命令来获取调用命令的消息。您可以使用 Client.delete_message 协程删除邮件。

You can obtain the message that called the command by passing the context with the command using the pass_context option. You can use the Client.delete_message coroutine to delete messages.

from discord.ext import commands

bot = commands.Bot(command_prefix='!')

@bot.command(pass_context=True)
async def deletethis(ctx):
    await bot.say('Command received')
    await bot.delete_message(ctx.message)
    await bot.say('Message deleted')

bot.run('token')

这篇关于discord.py执行命令后删除作者消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆