为什么要导入
commands
如果您不使用扩展名?利用
命令
扩展并将代码从
on_message
事件这使您可以利用
命令
扩展,如
converters
from discord.ext.commands import Bot
import discord
from collections import defaultdict
bot = Bot('!')
points = defaultdict(int)
@bot.event
async def on_ready():
print("Ready")
@bot.command(pass_context=True)
async def give(ctx, member: discord.Member):
points[member.id] += 1
bot.say("{} now has {} points".format(member.mention, points[member.id]))
@bot.command(pass_context=True)
async def points(ctx, member: discord.Member):
bot.say("{} has {} points".format(member.mention, points[member.id]))
bot.run('token')
至于持久化数据,您有几个选择。您可以将数据写入文件,然后将其读回,但我建议您考虑建立一个数据库。在其他地方和本网站上有大量的在线资源可以向您展示如何使用。如果您确实这样做了,那么您可能应该使用异步OUES数据库库,如
asyncpg
。