为不同的Discord服务器存储变量

时间:2020-11-09 16:03:37

标签: python discord.py

我正在为设置机器人的每台服务器存储不同的数据,因为我浏览了很多论坛,但没有找到符合我需要的内容,这是我的代码:

@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)

1 个答案:

答案 0 :(得分:1)

您要达到什么目标?只是存储每个行业的数据?您可以小规模json,或研究大型数据库,例如MySQLMongoDB