Недавно переписал своего бота под работу с командами и кнопками через библиотеки discord_slash и discord_components соответственно. Но случилась беда: при попытке отправки Embed'а с кнопками выскакивает ошибка:
An exception has occurred while executing command `embed`:
Traceback (most recent call last):
File "C:\Users\K0w0Mei\AppData\Local\Programs\Python\Python39\lib\site-packages\discord_slash\client.py", line 1353, in invoke_command
await func.invoke(ctx, **args)
File "C:\Users\K0w0Mei\AppData\Local\Programs\Python\Python39\lib\site-packages\discord_slash\model.py", line 210, in invoke
return await self.func(*args, **kwargs)
File "C:\Users\K0w0Mei\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 374, in __call__
return await self.callback(*args, **kwargs)
File "c:\Users\K0w0Mei\Documents\VAYO\VAYO.py", line 469, in embed
await channel.send(
File "C:\Users\K0w0Mei\AppData\Local\Programs\Python\Python39\lib\site-packages\discord_slash\dpy_overrides.py", line 323, in send_override
return await send(channel, *args, **kwargs)
File "C:\Users\K0w0Mei\AppData\Local\Programs\Python\Python39\lib\site-packages\discord_slash\dpy_overrides.py", line 300, in send
data = await state.http.send_message(
File "C:\Users\K0w0Mei\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 156, in request
kwargs['data'] = utils.to_json(kwargs.pop('json'))
File "C:\Users\K0w0Mei\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\utils.py", line 328, in to_json
return json.dumps(obj, separators=(',', ':'), ensure_ascii=True)
File "C:\Users\luchk\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 234, in dumps
return cls(
File "C:\Users\K0w0Mei\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\K0w0Mei\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Users\K0w0Mei\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Button is not JSON serializable
Проблема в том, что раньше такой же код, но в другом боте, работал адекватно. С чем связана проблема?
Вот нужные строчки кода:
from asyncio.tasks import sleep
from logging import error
from typing import Counter
import discord
import asyncio
import sqlite3
import config as cfg
from discord_components import DiscordComponents, Button, ButtonStyle
from discord_slash import SlashCommand,SlashContext
from discord_slash.utils.manage_commands import create_option
from discord.ext import commands
intents = discord.Intents().all()
bot = commands.Bot(command_prefix='/', intents=intents) # Префикс для команд
slash = SlashCommand(bot, sync_commands=True)
@bot.event
async def on_ready():
DiscordComponents(bot)
print('VAYO заработал под профилем {0.user}'.format(bot))
@slash.slash(
name = "embed",
description = "Обновить кол-во полученных заказов.",
options = []
)
@bot.command(aliase = ["embed"])
async def embed(ctx):
channel = bot.get_channel(cfg.Config[0])
await channel.send(
embed = discord.Embed(title = "VAYO", description = """Тестовый текст""", colour=1752220, timestamp = ctx.created_at),
components = [Button(custom_id = "Order", label = 'Оформить текст')])
Замечу, что при удалении кнопки, Embed отправляется спокойно.