【发布时间】:2020-12-25 09:55:07
【问题描述】:
如果标题没有多大意义,我很抱歉。所以我有一个我想要的不和谐机器人,所以每次有人说“鸡蛋”时,它都会给他们一分。如果他们不说鸡蛋,它会将他们的分数设置为之前分数的一半,并四舍五入,所以它没有小数。我尝试使用 Pickle 库保存到文件,但它看起来不正确,就像它的组织方式与我的组织方式不同,它似乎只是尽可能地保存了最少的内容。这是我的代码目前的样子。
import discord
from discord.ext import commands
TOKEN = 'token'
bot = commands.Bot(command_prefix='!')
@bot.event
async def on_ready():
print(f'Logged in as: {bot.user.name}')
print(f'With ID: {bot.user.id}')
@bot.command()
async def ping(ctx):
await ctx.send('Pong! Latency: {0}'.format(round(bot.latency, 1)))
@bot.event
async def on_message(message):
await bot.process_commands(message)
if message.channel.id == channel_id:
if message.author == bot.user:
return
else:
if ''.join(message.content.split()).lower() == "egg":
return
else:
await message.channel.send(
"{} You fool. You absolute buffoon, it is illegal to say anything other than 'egg' in this server. I hope you feel the shame in side you. Us only saying 'egg' in this channel brings peace to our server, and you thinking your above everyone? above ME? You {}, have messed up. I want you to take a long time to reflect on your self.".format(message.author.mention, message.author.mention))
else:
return
bot.run(TOKEN)
我知道这是非常随机的。我的最终目标是拥有所有说鸡蛋的用户的文件,以及他们当前的分数。如果您不想说如何给他们积分,我也许可以弄清楚。如果您有任何问题,我会尽力解答。
【问题讨论】:
-
您可以尝试
SQLite之类的库或yaml、json或txt之类的文件。对于这个程序,我更喜欢SQLite或json。 -
@Nurqm 感谢您的评论,我会研究 SQLite 和 json。
-
@Nurqm 我用 json 做实验,但我似乎无法理解它,我无法理解 SQLite,所以我不知道如何使用这些库达到我的最终目标.如果你能,你能回答这个问题吗?可能解释我需要做什么,或者怎么做?
-
您应该使用其中之一。我不能从一开始就教你整个图书馆。
-
我也推荐 SQLite 和 MySQL。它们非常简单高效。 MySQL 数据库是我目前用来存储玩家信息的数据库。它们与 RPG 不和谐机器人配合得非常好。
标签: python python-3.x discord discord.py discord.py-rewrite