我目前已經制作了一個具有經濟資料庫(json 格式)的不和諧機器人。但是,我不希望這種經濟資訊在服務器之間傳輸(當它添加到多個服務器時),而是希望每個服務器都有一個新的 json 檔案。誰能告訴我不和諧機器人如何判斷它是否在新服務器中以及如何為該服務器創建新的 json 檔案(無需我將其添加到我的檔案中)。
如果有其他方法而不為每個服務器創建新檔案,我也愿意聽取任何想法:)
uj5u.com熱心網友回復:
discord.py有一個on_guild_join事件,你可以監控它來檢測新的公會。例如,您可以創建一個字典,使用 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/490946.html
