Python 即使bot重新加载,也可以保留内存中的角色反应消息的系统

Python 即使bot重新加载,也可以保留内存中的角色反应消息的系统,python,python-3.x,discord,discord.py,discord.py-rewrite,Python,Python 3.x,Discord,Discord.py,Discord.py Rewrite,我需要python中discord机器人的帮助,我有一个命令,允许在消息上放置角色反应 它工作得很好,但我想知道是否有可能确保bot将用户输入的数据(角色、消息id和反应)保存在内存中,以便即使我重新加载bot,它也能继续工作?我想我需要一个数据库什么的,但如果你能给我一些建议 代码如下 import discord import discord.ext from discord.ext import commands from datetime import datetime bot =

我需要python中discord机器人的帮助,我有一个命令,允许在消息上放置角色反应

它工作得很好,但我想知道是否有可能确保bot将用户输入的数据(角色、消息id和反应)保存在内存中,以便即使我重新加载bot,它也能继续工作?我想我需要一个数据库什么的,但如果你能给我一些建议

代码如下

import discord
import discord.ext 
from discord.ext import commands
from datetime import datetime

bot = commands.Bot

class Automod(commands.Cog):

    def __init__(self, bot):
        self.bot = bot
    
    bot.reaction_roles = []

    @commands.Cog.listener()
    async def on_raw_reaction_add(self, payload):
        for role, msg, emoji in bot.reaction_roles:
            if msg.id == payload.message_id and emoji == payload.emoji.name:
                await payload.member.add_roles(role)
    
    #SET REACTION ROLE
    @commands.command(name="p!set-reaction", aliases=["set-reaction"])
    @commands.has_permissions(administrator=True)
    async def set_reaction(self, ctx, role: discord.Role=None, msg: discord.Message=None, emoji=None):
        """➡️ Set a role reaction on message """
        if role != None and msg != None and emoji != None:
            await msg.add_reaction(emoji)
            bot.reaction_roles.append((role, msg, emoji))
            await ctx.message.delete()
        
        else:
            await ctx.send("**Error:** Missing arguments, **[p!set-reaction <Role Name> <Message ID> <Emoji>]**")

    @set_reaction.error
    async def set_reaction_error(self, ctx, error):
        if isinstance(error, commands.MissingPermissions):
            await ctx.send("**Error:** You must have `administrator` permission to do that. ❌")
导入不一致
导入discord.ext
从discord.ext导入命令
从日期时间导入日期时间
bot=commands.bot
类Automod(commands.Cog):
def uuu init uuuu(自我,机器人):
self.bot=bot
bot.reaction_角色=[]
@commands.Cog.listener()
原始反应添加上的异步定义(自身,有效负载):
对于bot.reaction\u角色中的角色、msg和表情符号:
如果msg.id==payload.message_id和emoji==payload.emoji.name:
等待有效负载。成员。添加_角色(角色)
#设定反应角色
@commands.command(name=“p!set reaction”,别名=[“set reaction”])
@commands.has_权限(administrator=True)
异步def set_反应(self、ctx、role:discord.role=None、msg:discord.Message=None、emoji=None):
"""➡️ 在消息“”上设置角色反应
如果角色!=无和味精!=无和表情符号!=无:
等待消息添加反应(表情符号)
bot.reaction\u roles.append((角色、消息、表情符号))
等待ctx.message.delete()
其他:
等待ctx.send(“**错误:**缺少参数,***[p!设置反应]**”)
@设置错误
异步def设置\反应\错误(自身、ctx、错误):
如果isinstance(错误,commands.MissingPermissions):
等待ctx.send(“**错误:*”您必须具有“管理员”权限才能执行此操作。❌")

我希望这很清楚,但不要问我更多细节……如果您不保存任何敏感日期,那么这可能是组织和保存数据的最简单方法。