Discord Bot 提取角色信息

Discord Bot Extract characters information

提问人:AliGxor 提问时间:11/15/2023 更新时间:11/15/2023 访问量:15

问:

嘿,伙计们,我正在尝试向我的 discord 机器人添加另一个命令,它应该向 raider.io 角色发送 GET 请求,例如 https://raider.io/characters/us/sargeras/Cosmiccs 并提取 Name-Realm Score Guild(如果角色在任何公会中),并将结果发送到聊天室或任何地方。这是我的代码不起作用,如果您能帮助我,我将不胜感激

elif 'raider.io/characters/' in message.content:
    raider_url = message.content.split('raider.io/characters/')[-1].split('/')[0]
    response = requests.get("https://raider.io/characters/" + raider_url)
    if response.status_code==200:
        soup = BeautifulSoup(response.content, 'html.parser')
        character_name_tag = soup.find('span', class_='rio-text-shadow--heavy')
        character_name = character_name_tag.text.strip() if character_name_tag else None
        guild_tag = soup.find('a', class_='rio-realm-link', href=re.compile(r'/guilds/'))
        guild_name = guild_tag.text.strip() if guild_tag else None
        realm_tag = soup.find('a', class_='rio-realm-link rio-text-shadow--normal', href=re.compile(r'/home/eu/(.*?)'))
        realm_url = realm_tag['href'] if realm_tag else None
        if realm_url:
            realm_name_match = re.search(r'/home/eu/(.*?)', realm_url)
            realm = realm_name_match.group(1) if realm_name_match else None
        else:
            realm=None
        score_tag = soup.find('span', class_='rio-badge-size--medium')
        score_text = score_tag.text.strip() if score_tag else None
        score_pattern = re.compile(r'[\d,]+')
        score_match = score_pattern.search(score_text)
        score = score_match.group() if score_match else None
        await message.channel.send("\n Character Information\n Character : " + character_name + realm + "\n" +"Character Score : " + score + "\n Character Guild : " + guild_name)
    else:
        print(f"Error: Something went wrong DM STAFF/Manager for Info {response.status_code}")
        return None
Python Discord 机器人

评论

0赞 Robert 11/15/2023
你说的“不起作用”到底是什么意思?你如何运行你的代码?当你运行它时会发生什么,你期望会发生什么?有错误吗?这是关于不和谐还是只是关于刮擦?请编辑并删除您的问题中不相关的部分,并提供一个最小的可重复示例

答: 暂无答案