【发布时间】:2021-02-08 02:15:01
【问题描述】:
我正在尝试编写一个函数,使用用户发送的命令删除消息。
例如:
- 用户发送命令 /delmes
- Bot 向命令发送响应
- Bot 删除用户发送的消息
到目前为止,我能找到的所有东西(这对我都有帮助)就是这个 Stack Overflow 线程:discord.py delete author message after executing command
但是当我使用代码时,如解决方案中所述,我只收到 AttributeError: 'Bot' object has no attribute 'delete_message'。
discord.py API 参考 (https://discordpy.readthedocs.io/en/latest/migrating.html#models-are-stateful / https://discordpy.readthedocs.io/en/latest/api.html?highlight=delete%20message#message) 仅显示某些代码已随较新版本发生更改。 可以这么说 client.delete_message 将更改为 Message.delete(),如果我解释正确的话!
将代码更改为我认为必须的代码后,我收到了:NameError: name 'Message' is not defined
这是我最后时刻的代码。 (我对 discord.py 比较陌生,只在学校使用过 Python)
import discord
from discord.ext import commands
import random
import json
client = commands.Bot(command_prefix = '/', case_insensitive=True)
@client.command(pass_context=True)
async def delcommes(ctx):
await ctx.send("This is the response to the users command!")
await Message.delete(ctx.message, delay=3)
【问题讨论】:
标签: discord discord.py