#interation error

1 messages · Page 1 of 1 (latest)

peak flame
#

hello, I have a problem that I just didn't do, but I always have an interaction error in the selection menu (sorry if it's not clear I'm Russian and I can't handle this problem)

#
import disnake
from disnake.ext import commands
import os
import json
from functions.EmbedCommandsFunctions import EmbedCommandsFunctions

intents = disnake.Intents.default()
intents.typing = True
intents.presences = True
intents.message_content = True

with open('config.json', 'r') as f:
    config = json.load(f)

TOKEN = config["token"]
PREFIXES = config["prefixes"]

bot = commands.Bot(command_prefix=PREFIXES, intents=intents)
bot.owner_id = config["owner_id"]

embed_cog = EmbedCommandsFunctions(bot)
bot.add_cog(embed_cog)


@bot.event
async def on_ready():
    print(f'Бот запущен как - {bot.user.name}')
    print(disnake.__version__)
    # Загрузка всех команд из папки "economy"
    for filename in os.listdir('./economy'):
        if filename.endswith('.py') and not filename.startswith('__'):
            bot.load_extension(f'economy.{filename[:-3]}')
            print(f"Расширение '{filename[:-3]}' загружено.")
        else:
            print(f"Файл/папка '{filename}' не является файлом .py")


@bot.event
async def on_command(ctx):
    print(f"Получена команда: '{ctx.command}' от пользователя '{ctx.author}'")


@bot.event
async def on_command_error(ctx, error):
    print(f"Ошибка при выполнении команды '{ctx.command}': {error}")


@bot.command(name="команды")
async def команды(ctx):
    view = disnake.ui.View(timeout=None)
    select = disnake.ui.Select(
        placeholder="Выберите категорию",
        min_values=1,
        max_values=1,
        custom_id="selectCommands"
    )
    select.add_option(
        label="Основное",
        value="osnovnoe",
        description="Покажет основные команды бота",
        emoji="![Discord](https://cdn.discordapp.com/emojis/1108784757115981875.webp?size=128 "Discord")"
    )
    select.add_option(
        label="Модерация",
        value="moderation",
        description="Покажет команды модерации",
        emoji="![Moderator1](https://cdn.discordapp.com/emojis/1108784793082138704.webp?size=128 "Moderator1")"
    )
    select.add_option(
        label="Экономика",
        value="economy",
        description="Покажет команды экономики",
        emoji="![Nitro](https://cdn.discordapp.com/emojis/1108784798299848726.webp?size=128 "Nitro")"
    )
    select.add_option(
        label="Развлечения",
        value="funny",
        description="Покажет развлекательные команды",
        emoji="![Gaming1](https://cdn.discordapp.com/emojis/1108784762249826324.webp?size=128 "Gaming1")"
    )
    view.add_item(select)

    if bot.user.avatar:
        bot_avatar_url = bot.user.avatar.url
    else:
        bot_avatar_url = "https://cdn.discordapp.com/embed/avatars/1.png"

    if ctx.author.avatar:
        user_avatar_url = ctx.author.avatar.url
    else:
        user_avatar_url = "https://cdn.discordapp.com/embed/avatars/0.png"

    color = disnake.Colour.from_rgb(57, 5,161)

    embed = disnake.Embed(
        title="Команды",
        description="Выбери категорию для просмотра её команд",
        colour=color
    )
    embed.set_author(name=ctx.author.name, icon_url=user_avatar_url)
    embed.set_thumbnail(url=bot_avatar_url)

    message = await ctx.send(embed=embed, view=view)

    def check(interaction):
        return interaction.user == ctx.author and interaction.message.id == message.id

    interaction = await bot.wait_for("select_option", check=check)
    selected_option = interaction.values[0]

    if selected_option == "osnovnoe":
        await embed_cog.osnovnoe(interaction)
        print("Выбрана опция 'osnovnoe'")
    elif selected_option == "moderation":
        await embed_cog.moderation(interaction)
        print("Выбрана опция 'moderation'")
    elif selected_option == "economy":
        await embed_cog.economy(interaction)
        print("Выбрана опция 'economy'")
    elif selected_option == "funny":
        await embed_cog.funny(interaction)
        print("Выбрана опция 'funny'")

bot.run(TOKEN)
#

and there are also no errors in the console

random jewel
#

Everything is bad. Don't use views if you're using wait for, use low level components and you need to answer to an interaction

peak flame
#

how's that?

#

@random jewel

tiny sailBOT
#
interactions/low_level_components.py

An example on how to send and process components without using views.

random jewel
#

@peak flame

peak flame
#

buttons?

#

or another version of the selection menu

random jewel
#

Use wait for

peak flame
#

ok

#

thanks

random jewel
#
        try:
            dropdown_interaction = await inter.bot.wait_for(
                "dropdown",
                check=lambda i: i.component.custom_id == f"blahblah-{inter.id}"
                and i.user.id == inter.user.id,
                timeout=200,
            )
        except asyncio.TimeoutError:
            return```
#

@peak flame example

#

and its wait_for dropdown not wait_for select_option

peak flame
#

I'll fix it later, thanks

peak flame
#

hi, I don't run a function from another script, but if I do print or send a message directly, then everything works @random jewel

#

@bot.listen("on_dropdown")
async def cool_select_listener(inter: disnake.MessageInteraction):
if inter.values == ['osnovnoe']:
EmbedCommandsFunctions.osnovnoe
else:
await inter.response.send_message(f"Неизвестная опция {inter.values}")

#

@random jewel help please

random jewel
peak flame
#

pamagi pliz

random jewel
#

whats the problem?

spare arch
peak flame
#

I didn't notice right away