【问题标题】:Python Discord bot delete users messagePython Discord bot 删除用户消息
【发布时间】:2020-08-25 08:25:04
【问题描述】:

我正在 python3 中开发一个不和谐机器人(discord.py 1.3.3,不和谐 1.0.1),我需要删除用户消息,但我不知道如何正确调用协程。

我查看了someotherthreads,并尝试查看documentation(和discord.py docs),但我无法弄清楚。

这是我正在测试的内容:

import discord
from discord.ext import commands

TOKEN = os.getenv('DISCORD_TOKEN')
bot = commands.Bot(command_prefix='!')

@bot.command(name='deleteme', help='testing command for dev use')
async def deleteme(ctx):
    msg = ctx.message.id
    print(f'DEBUG: message id is {msg}')
    await msg.delete
    # await ctx.delete(msg, delay=None)  #nope
    # await ctx.delete_message(ctx.message)  #nope
    # await bot.delete_message(ctx.message)  #nope
    # await command.delete_message(ctx.message)  #nope
    # await discord.Client.delete_message(msg)  #nope

运行此命令会返回带有 ID 号的控制台调试消息,但不会删除该消息。如果我在await msg.delete 之后添加调试打印行,它不会返回。所以这告诉我脚本挂在哪里。也就是说,我仍然无法弄清楚正确的命令应该是什么。

机器人服务器权限包括“管理消息”

【问题讨论】:

    标签: python python-3.x discord discord.py discord.py-rewrite


    【解决方案1】:

    为了删除一条消息,你必须使用discord.Message 对象,例如,你会这样做:

    await ctx.message.delete()
    

    delete()协程是discord.Message的一个方法

    【讨论】:

    • 完美!非常感谢。
    猜你喜欢
    • 1970-01-01
    • 2021-10-18
    • 2021-01-28
    • 2018-11-07
    • 2020-12-03
    • 2017-10-25
    • 2018-07-24
    • 2018-09-07
    • 1970-01-01
    相关资源
    最近更新 更多