Discord Bot Python数据库

发布于 2025-02-07 03:44:45 字数 214 浏览 0 评论 0原文

我目前已经制作了一个具有经济数据库(JSON格式)的Discord机器人。但是,我不希望这些经济信息在服务器之间携带(当它添加到多个服务器中时),而是希望每个服务器都有一个新的JSON文件。任何人都可以告诉我,一个不和谐机器人如何在新服务器中判断它是否在新服务器中以及如何为该服务器创建新的JSON文件(没有我将其添加到文件中)。

如果没有其他方法没有为每个服务器制作新文件,我也可以听到任何想法:)

I currently have made a discord bot that has an economy data base (in json format). However, I do not want this economy information to carry between servers (when its added to multiple servers) but instead want a new json file for each server. Can anyone tell me how a discord bot can tell if its in a new server and how to create a new json file for that said server (without me adding it to my file).

If there is other methods without making a new file for each server, I am open to hear any ideas as well :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如梦 2025-02-14 03:44:45

on_guild_join您可以监视以检测新的guilds。您可以制作 dictionary 使用guild ID作为钥匙,例如,JSON对象作为值。

@client.event
def on_guild_join(guild):
    guild_db = economy_db.get(str(guild.id))
    if not guild_db:  # If the guild hasn't been visited yet
        economy_db[str(guild.id)] = dict()
        # Do your stuff to create a new economic system
    else:
        # In case the guild already exists in the database
        # Do stuff here

discord.py has a on_guild_join event you can monitor to detect new guilds. You could make a dictionary that uses the Guild ID as a key, and the JSON object as a value for example.

@client.event
def on_guild_join(guild):
    guild_db = economy_db.get(str(guild.id))
    if not guild_db:  # If the guild hasn't been visited yet
        economy_db[str(guild.id)] = dict()
        # Do your stuff to create a new economic system
    else:
        # In case the guild already exists in the database
        # Do stuff here
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文