Python discord bot embed. Ошибка Command raised an exception: HTTPException: 400 Bad Request (error code: 50035)
Все хорошо работало, но вдруг перестал работать await channel.send(embed=embed), pl.clear(), n.clear(), q.clear(), и не хочет запускаться даже после отмены всех действий до момента когда он работал. Не пойму в чем проблема если даже все списки которые он должен вывести выводятся с помощью print нормально.
Ошибка:
[BOT] Бот Крякер Младший запущен
START
['ZEMLIBOGA +180'] ['1/8'] ['']
Ignoring exception in command start:
Traceback (most recent call last):
File "D:\Python\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "D:\PROJECT\BOT\main.py", line 54, in start
await channel.send(embed=embed), pl.clear(), n.clear(), q.clear()
File "D:\Python\lib\site-packages\discord\abc.py", line 1064, in send
data = await state.http.send_message(channel.id, content, tts=tts, embed=embed,
File "D:\Python\lib\site-packages\discord\http.py", line 254, in request
raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embed.fields.2.value: This field is required
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\Python\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "D:\Python\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "D:\Python\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embed.fields.2.value: This field is required
Код main.py:
import config
import discord
from discord.ext.commands import Bot
import requests
import sys
from lib.parsing import *
import time
import asyncio
bot = Bot( command_prefix = '.')
cycles = dict(start=True)
p = Person()
p.get_game()
p.get_parse()
game = p.game_list
@bot.event
async def on_ready():
print('[BOT] Бот ' + bot.user.name + ' запущен')
@bot.command()
async def stop(ctx):
print('STOP')
cycles["start"] = False
@bot.command()
async def start(ctx):
channel = bot.get_channel(int(824948332510052355))
n = []
pl = []
q = []
pl.clear(), n.clear(), q.clear()
cycles["start"] = True
while cycles["start"]:
print('START')
for s in game:
if re.search('zeml', str(s)):
n.append(s['NAME'])
pl.append(s['PLAYERS'])
q.append(s['QUANTITY'])
elif re.search('ZEML', str(s)):
n.append(s['NAME'])
pl.append(s['PLAYERS'])
q.append(s['QUANTITY'])
embed = discord.Embed(title='Информация об игре', color=0x00ff00)
embed.add_field(name='Количество игроков:', value=''.join(q))
embed.add_field(name='Название игры:', value=''.join(n), inline=False)
embed.add_field(name='Игроки', value=''.join(pl), inline=False)
print(n, q, pl)
time.sleep(5)
await channel.send(embed=embed), pl.clear(), n.clear(), q.clear()
p.get_game()
p.get_parse()
time.sleep(5)
bot.run(config.TOKEN)
Код parsing.py:
import time
import re
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
class Person:
def get_game(self):
try:
with open("parse.html", "w", encoding='utf-8') as file: #Сохранение контента сайта
file.write(driver.page_source)
file.close()
self.num = driver.find_element_by_xpath('//*[@id="botstat"]/tr[1]/td[2]').text #Сохранение числа не начатых игр
driver.find_element_by_xpath('//*[@id="botstat"]/tr[1]/td[2]').click() #Симуляция движенй мышки для обновления контента
move = driver.find_element_by_xpath('//*[@id="gamestat"]/tr[1]/td[5]/button') #
ActionChains(driver).move_to_element(move).perform()
except Exception as ex:
print(ex)
def get_parse(self):
#Открытие контента сайта
with open('parse.html', 'r', encoding='utf-8') as file:
f = file.read()
soup = BeautifulSoup(f, "lxml")
#Выделение каши
items = soup.find_all("tr", class_="gamebackgroud", limit=int(self.num)) #Число не начатых игр которые нужно запарсить
self.game_list = []
#Добавление в список активных игр
for item in items:
try:
self.game_list.append({
'QUANTITY':driver.find_element_by_xpath('//*[@id="gamestat"]/tr[1]/td[2]').text,
'NAME':item.find('td', class_='gamename').get_text(),
'PLAYERS':item.find('div', class_='ui horizontal list').get_text(', ')
})
except:
break
finally:
file.close()
#print('.......Список игр.......\n',self.game_list, '\n........................')
#def get_data(self):
options = webdriver.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
driver = webdriver.Chrome(options=options)
driver.get('https://irinabot.ru')
# headless mode
#options.add_argument("--headless")
#options.headless = True
time.sleep(5)