首页 > 解决方案 > 如何删除 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)

标签: pythondiscorddiscord.py

解决方案


您必须放在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

推荐阅读