【问题标题】:Storing variables for different discord servers为不同的不和谐服务器存储变量
【发布时间】:2020-11-10 00:45:04
【问题描述】:

我正在尝试为我设置机器人的每个服务器存储不同的数据,因为我浏览了许多论坛,但没有找到任何适合我需要的东西,这是我的代码:

@client.command()
async def pop(ctx, arg):
    global pop2
    pop2 = arg

    URL = 'https://www.battlemetrics.com/servers/rust/' + arg
    page = requests.get(URL)

    soup = BeautifulSoup(page.content, 'html.parser')
    title = soup.find("h2").get_text()
    title = title.replace('Connect', '')
    soup = BeautifulSoup(page.content, 'html.parser')

    page = soup.find('dl', class_='css-1i1egz4')

    pop = page.find("dt", text="Player count")

    status = page.find("dt", text="Status")

    status1 = status.findNext("dd").get_text()
    pop1 = pop.findNext("dd").get_text()
    if status1 == "offline":
        colour = 0xff0000
    elif status1 == "online":
        colour = 0x33ff0a
    elif status1 == "dead":
        colour = 0xff0000
    embed = discord.Embed(title=title, description=status1, color=colour)
    embed.add_field(name="Server", value=URL, inline=False)
    embed.add_field(name="pop", value=pop1, inline=False)
    await ctx.send("The server has been set to:")
    await ctx.send(embed=embed)

【问题讨论】:

    标签: python discord.py


    【解决方案1】:

    你想达到什么目的?只是存储每个公会的数据?您可以在小范围内使用 json,或者查看更大的数据库,例如 MySQLMongoDB

    【讨论】:

    • 我如何将它作为 JSON 存储在 discord.py 中?
    • json.load(openFile) 将返回一个python字典,然后将其保存json.dump(dictionary, openFile)
    猜你喜欢
    • 2020-11-24
    • 2018-06-23
    • 2021-11-19
    • 2016-11-08
    • 2021-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-10
    相关资源
    最近更新 更多