不和谐和机器人制造:我似乎不能让我的机器人发布一个网络解析材料

2024-04-19 09:40:08 发布

您现在位置:Python中文网/ 问答频道 /正文

第一个帖子!耶。。。所以。我在做机器人,遇到了一些麻烦。在

我似乎无法让我的机器人在调用我编写的“stats”命令后,在我的discord频道中发布web解析的内容。我一接到命令就得到“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:

^{pr2}$

有人知道我如何克服HTTP403问题吗?让我的代码将表值粘贴到聊天中?在

编辑:已经过了403,现在卡在401:

回溯(最近一次呼叫): 文件“C:\Python36_64\lib\site packages\discord\客户端.py“,第307行,在运行事件中 getattr(self,event)的产量(*args,**kwargs) “文件”halobot.py“,第43行,on峎 等待client.send_消息(消息.频道,content=stringdata) 文件“C:\Python36_64\lib\site packages\discord\客户端.py“,第1152行,发送消息中 数据=产量self.http.send_消息(频道编号,内容,公会编号=公会编号,tts=tts,嵌入=嵌入) 文件“C:\Python36_64\lib\site packages\discord\http.py“,第200行,请求中 引发HTTPException(r,data) discord.errors.HTTPException:未授权(状态代码:401):401:未授权


Tags: 文件frompyimportclient消息messagehtml