python - 如何删除 discord.py 中的用户命令消息?
问题描述
我有这个命令的代码。如何删除用户命令消息?
@bot.command()
@commands.has_role("Referee")
async def game(ctx, winner, loser, score, MVP):
teams = winner + " vs " + loser
embed = discord.Embed(title = "Shell League Game | Season 1 ", color = 0xfca426)
embed.add_field(name = "Teams", value = teams, inline = False)
embed.add_field(name = "Score", value = score, inline = False)
embed.add_field(name = "MVP", value = MVP, inline = False)
await ctx.send(embed = embed)
解决方案
您必须放在await ctx.message.delete()
函数定义的开头。干得好:
@bot.command()
@commands.has_role("Referee")
async def game(ctx, winner, loser, score, MVP):
await ctx.message.delete() # deletes author's command message
# rest of your command's code
推荐阅读
- swift - 在导航控制器中的视图控制器之间传递数据
- python-3.x - 将 .py 文件转换为 .pyd 文件
- python - 不明白为什么python在重复调用同一个函数时不重用参数
- laravel - 将 laravel 部署到谷歌云平台时出现 PHP 错误
- spring-boot - spring REST RequestMethod 如何映射 http LOCK 和 UNLOCK RequestMapping?
- html - 如何减小 mdbootstrap 中按钮的大小?
- git - 如何使用 gitlab-ci 作业推送到 gitlab 存储库?
- slim - 苗条中的 $response->withRedirect() 方法不渲染中间件中创建的树枝的全局变量
- javascript - 如何构建这些数据?JS
- mongodb - Mongodb 针对本地字符串 id 和外部表中的 _id 查询 $lookup