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