Ошибка в строке bot = commands.Bot(command_prefix="/")
Код:
bot = commands.Bot(command_prefix="/")
import discord
from discord.ext import commands
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
# Конфигурация Selenium
chrome_options = Options()
chrome_options.add_argument("--headless") # Запуск браузера в фоновом режиме
driver = webdriver.Chrome(options=chrome_options)
wait = WebDriverWait(driver, 10)
# Конфигурация Дискорд бота
bot = commands.Bot(command_prefix="/")
@bot.event
async def on_ready():
print(f"Bot connected: {bot.user.name}")
@bot.command()
async def start(ctx):
await ctx.send("Start...")
# Переход на сайт Aternos
driver.get("https://aternos.org/go")
# Вход в аккаунт
login_input = wait.until(EC.presence_of_element_located((By.ID, "user")))
password_input = wait.until(EC.presence_of_element_located((By.ID, "password")))
login_input.send_keys("секрет")
password_input.send_keys("секрет")
password_input.send_keys(Keys.RETURN)
# Ожидание загрузки страницы сервера
wait.until(EC.url_to_be("https://aternos.org/server"))
# Проверка состояния сервера
status_button = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, ".statuslabel-label")))
server_status = status_button.text
if server_status == "Offline":
# Нажатие кнопки "Включить"
start_button = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".start")))
start_button.click()
await ctx.send("Server is starting...")
else:
await ctx.send("Server is on.")
# Запуск бота
bot.run("")
Ошибка:
3.17s - Error in linecache.getline('D:\\Павел\\Эксперименты\\DiscordBot\\main.py', 19, f_globals)
Traceback (most recent call last):
File "_pydevd_bundle/pydevd_cython.pyx", line 546, in _pydevd_bundle.pydevd_cython.PyDBFrame._handle_exception
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 47, in getlines
return updatecache(filename, module_globals)
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 137, in updatecache
lines = fp.readlines()
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xca in position 360: invalid continuation byte
0.00s - Error on build_exception_info_response.
Traceback (most recent call last):
File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 1452, in build_exception_info_response
line_text = linecache.getline(original_filename, lineno)
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 47, in getlines
return updatecache(filename, module_globals)
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 137, in updatecache
lines = fp.readlines()
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xca in position 360: invalid continuation byte
0.03s - Error on build_exception_info_response.
Traceback (most recent call last):
File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_comm.py", line 1452, in build_exception_info_response
line_text = linecache.getline(original_filename, lineno)
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 16, in getline
lines = getlines(filename, module_globals)
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 47, in getlines
return updatecache(filename, module_globals)
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\linecache.py", line 137, in updatecache
lines = fp.readlines()
File "C:\Users\pahan\AppData\Local\Programs\Python\Python38\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xca in position 360: invalid continuation byte
Ответы (1 шт):
Автор решения: BArbosspirat
→ Ссылка
intents = discord.Intents.default()
intents.members = True
intents.message_content = True
bot = commands.Bot(config['prefix'], intents=intents)
во всех моих ботах используется эти строчки, попробуйте