首页 文章

不和谐和机器人制作:我似乎无法让我的机器人发布网络解析材料

提问于
浏览
1

第一篇文章!是的......所以 . 我制作机器人并遇到了麻烦 .

我似乎不能让我的机器人在调用我写的“stats”命令时在我的不和谐 Channels 中发布网络解析的资料 . 在调用命令时我得到“403未授权”!我试图显示一些统计数据 .

使用的python:

import asyncio
import datetime
from difflib import SequenceMatcher
import json
import urllib
from bs4 import BeautifulSoup
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import requests
import html2text
from html.parser import HTMLParser
from html.entities import name2codepoint
client = discord.Client()

bot = commands.Bot(command_prefix='!', description='a halo server status check bot.')
#responce = requests.get(url)
#responce.text[:100]
import urllib.request

url = "http://chiperdilly.com/cestatstext/test.html"
html = urllib.request.urlopen(url).read()
mystr = html.decode("utf8")

soup = BeautifulSoup(html, "html.parser")
stringdata = (element.text for element in soup.find_all("div", "value"))
chanel = client.get_channel("437430094445674500")
for script in soup(["script", "style"]):
    script.extract

@bot.event
async def on_ready():
    print('dont let dreams be dreams...')
    print(bot.user.name)
    print(bot.user.id)

@bot.event
async def on_message(message):
    if message.content.startswith('!stats'):
        #await client.send_message(message.channel, content=stringdata)
        bot.say(message.channel, stringdata)
        #print(stringdata)
bot.run(myTOKEN)

使用的HTML:

<!DOCTYPE html>
<html>
    <head>
        <title>Halo CE Server Stats tool</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <meta http-equiv="refresh" content="10">
        <style type="text/css">
        </style>

        <link href="css/rhp_customized.css" rel="stylesheet" type="text/css">
    </head>
    <body background="images/hp_bg.jpg">
        <table width="699" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><img src="images/hp_top.jpg" width="699" height="58" /></td>
  </tr>
  <tr>
    <td background="images/hp_tablebg.jpg"><img src="images/hp_serverinfo.jpg" width="699" height="44" /></td>
  </tr>
  <tr>
    <td background="images/hp_tablebg.jpg" style="padding-left: 35px; padding-right: 50px;">
      <table width="600" border="0" align="center" cellpadding="3" cellspacing="1">
        <tr>
          <td valign="top">
            <div align="center" class="value"><strong><font size="+1">!tht_serber!</font></strong>
<span class="smalltext" class="value">Dedicated server v01.00.10.0621</span>

</div> <table width="100%"> <tr> <td> Address: <strong><a href="halogame.com:2302">halogame.com:2302</a></strong>
This is a <strong>public</strong> server
There are <b>1</b> / <b>16</b> players
Current game is <b>CTF</b> (CTF)
The Frag/Score Limit is <b>3</b> </td> <td valign="top"> <div align="center" class="value"><strong>Team Scores:</strong>
<span class="red"><b>Red Team: 0</b></span>
<span class="blue"><b>Blue Team: 0</b></span></div> </td> </tr> </table> </div> </td> <td> <div align="center" class="value"><a href="http://hce.halomaps.org/index.cfm?search=Bloodgulch"><img src="images/maps/bloodgulch.jpg" width="200" height="150" id="map_illustration" alt="Halo Bigtits map"></a>
<strong>Bloodgulch</strong></div>
</td> </tr> </table> </td> </tr> <tr> <td background="images/hp_tablebg.jpg"><img src="images/hp_playerinfo.jpg" width="699" height="47" /></td> </tr> <tr> <td background="images/hp_tablebg.jpg" style="padding-left: 35px; padding-right: 50px;"><table width="100%" border="0" cellpadding="3"> <tr> <td width="33%" class="bigbold" align="center"> Player Name </td> <td width="33%" class="bigbold" align="center"> Score </td> <td width="34%" class="bigbold" align="center"> Team </td> </tr> <tr> <td width="33%" align="center"> somedude </td> <td width="33%" align="center"> 0 </td> <td width="34%" align="center"> <span class="red"><strong>RED</strong></span> </td> </tr> </table></td> </tr> <tr> <td><img src="images/hp_bottom.jpg" width="699" height="49" /></td> </tr> </table>
</body> </html>

有谁知道我怎么能超越http 403问题?并获取我的代码将表值粘贴到聊天中?

编辑:过了403现在卡在401:

回溯(最近一次调用最后一次):文件“C:\ Python36_64 \ lib \ site-packages \ discord \ client.py”,第307行,在_run_event中从getattr得到(self,event)(* args,** kwargs)文件on_message中的“halobot.py”,第43行await client.send_message(message.channel,content = stringdata)send_message数据中的文件“C:\ Python36_64 \ lib \ site-packages \ discord \ client.py”,第1152行=来自self.http.send_message(channel_id,content,guild_id = guild_id,tts = tts,embed = embed)文件“C:\ Python36_64 \ lib \ site-packages \ discord \ http.py”,第200行,请求raise HTTPException(r,data)discord.errors.HTTPException:UNAUTHORIZED(status code:401):401:Unauthorized

1 回答

  • 0

    您的请求缺少请求标头 . 您必须指定Web服务器允许您连接的User-Agent标头 .

相关问题