【发布时间】:2020-05-05 13:32:24
【问题描述】:
您好,我正在尝试为 discord bot 发出命令,这样当我输入 .count 时它会显示 +1,但是如果我再次输入它会显示 +2,如果我再次输入它会显示 +3等等,如果有人知道该怎么做,请告诉我谢谢我已经尝试了很多东西,包括
COUNT = 0
def increment():
global COUNT
COUNT += 1
increment()
print(COUNT)
这不起作用只是停留 1
更新:刚刚尝试过
if "!counter" == message.content.lower():
await message.channel.send
def get_var_value(filename="store.dat"):
with open(filename, "a+") as f:
f.seek(0)
val = int(f.read() or 0) + 1
f.seek(0)
f.truncate()
f.write(str(val))
return val
your_counter = get_var_value()
print("This script has been run {} times.".format(your_counter))
这确实有点用,我不能让它在聊天中说出来“类型错误:对象方法不能用于'await'表达式”,它也不会根据用户是谁而改变命令是
【问题讨论】:
标签: python python-3.x discord.py discord.py-rewrite