#interation error
1 messages · Page 1 of 1 (latest)
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=""
)
select.add_option(
label="Модерация",
value="moderation",
description="Покажет команды модерации",
emoji=""
)
select.add_option(
label="Экономика",
value="economy",
description="Покажет команды экономики",
emoji=""
)
select.add_option(
label="Развлечения",
value="funny",
description="Покажет развлекательные команды",
emoji=""
)
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
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
An example on how to send and process components without using views.
@peak flame
Use wait for
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
I'll fix it later, thanks
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
pamagi pliz
whats the problem?
may be u going in ru disnake server
I didn't notice right away