如何计算命令执行的频率?
How do I count how often a command was executed?
我想通过机器人显示一个命令被执行了多少次。
为此,我已经在平台上进行了查询,并尝试了不同的方法。关于我的代码:
e = discord.Embed(color=discord.Colour.green())
user = ctx.author
e.title = f "New suggestion!"
e.set_footer(text=f"{user} | {user.id}")
e.description = f "**__Submitter:__**\n {ctx.author}"
e.add_field(name="__Suggestion:__", value=f"{text}")
e.set_thumbnail(url=ctx.message.author.avatar_url)
e.timestamp = datetime.utcnow()
await channel.send(embed=e)
await ctx.message.add_reaction("✅")
机器人应该在标题中添加Suggestion no. #number
,执行命令时会一次上升一个。我已经尝试过以下方法:
def __init__(self, bot):
self.bot = bot
self.counter = 0
#Shortened
e.title = f "Suggestion no. {self.counter}"
或者也可以:
e.title = f "Suggestion no. {self.counter + 1}
但这并没有帮助,那么我如何确保显示正确的数字,并且在机器人重启的情况下这个数字继续上升并且不会从头开始。
请注意,全局事件对我不起作用!
您实际上需要更新 counter
变量
self.counter += 1
e.title = f"Suggestion no. {self.counter}"
如果您希望变量在机器人重启后继续运行,您可以将其保存在 JSON 或文本文件中
我想通过机器人显示一个命令被执行了多少次。 为此,我已经在平台上进行了查询,并尝试了不同的方法。关于我的代码:
e = discord.Embed(color=discord.Colour.green())
user = ctx.author
e.title = f "New suggestion!"
e.set_footer(text=f"{user} | {user.id}")
e.description = f "**__Submitter:__**\n {ctx.author}"
e.add_field(name="__Suggestion:__", value=f"{text}")
e.set_thumbnail(url=ctx.message.author.avatar_url)
e.timestamp = datetime.utcnow()
await channel.send(embed=e)
await ctx.message.add_reaction("✅")
机器人应该在标题中添加Suggestion no. #number
,执行命令时会一次上升一个。我已经尝试过以下方法:
def __init__(self, bot):
self.bot = bot
self.counter = 0
#Shortened
e.title = f "Suggestion no. {self.counter}"
或者也可以:
e.title = f "Suggestion no. {self.counter + 1}
但这并没有帮助,那么我如何确保显示正确的数字,并且在机器人重启的情况下这个数字继续上升并且不会从头开始。 请注意,全局事件对我不起作用!
您实际上需要更新 counter
变量
self.counter += 1
e.title = f"Suggestion no. {self.counter}"
如果您希望变量在机器人重启后继续运行,您可以将其保存在 JSON 或文本文件中