问题
I have a private bot on discord, i've been trying to make him count a command and adding '+1' everytime I write that one command but it stays at 1 and can't go further : like this
I think what I want to do is to make it save the number of time the command has been writen and add +1 to this number ; Should I do a loop or something ?
Basically what I want is something like this in python for a discord bot : https://docs.nightbot.tv/commands/variables/count
回答1:
You're resetting your counter variable back to zero every time you call the function with the line
counter = 0
You can solve this by declaring the counter variable outside of the function and by removing the
counter = 0
line in the function afterwards.
回答2:
You're resetting your counter on every call, declaring your counter outside your function will solve the problem
counter = 0
async def cmg_thatcommand(self,channel):
...
counter+=1
...
return Response('you wrote that command {} time.' .format(counter))
来源:https://stackoverflow.com/questions/41675454/bot-counting-command-discord