bot counting command discord

ぃ、小莉子 提交于 2021-01-29 04:56:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!