Почему при вводе команды ничего не выдаёт
Когда я ввожу команду /tags или !tags он ничего не выводит
import disnake
from disnake.ext import commands
from disnake import TextInputStyle
# Subclassing the modal.
class MyModal(disnake.ui.Modal):
def __init__(self):
# The details of the modal, and its components
components = [
disnake.ui.TextInput(
label="Name",
placeholder="Foo Tag",
custom_id="name",
style=TextInputStyle.short,
max_length=50,
),
disnake.ui.TextInput(
label="Description",
placeholder="Lorem ipsum dolor sit amet.",
custom_id="description",
style=TextInputStyle.paragraph,
),
]
super().__init__(title="Create Tag", components=components)
# The callback received when the user input is completed.
async def callback(self, inter: disnake.ModalInteraction):
embed = disnake.Embed(title="Tag Creation")
for key, value in inter.text_values.items():
embed.add_field(
name=key.capitalize(),
value=value[:1024],
inline=False,
)
await inter.response.send_message(embed=embed)
async def on_error(self, error: Exception, inter: disnake.ModalInteraction):
await inter.response.send_message(f"An error occurred!\n```{error}```")
bot = commands.Bot(command_prefix="!")
@bot.slash_command()
async def tags(inter: disnake.AppCmdInter):
"""Sends a Modal to create a tag."""
await inter.response.send_modal(modal=MyModal())
bot.run("token")
Ответы (1 шт):
Автор решения: endless light year
→ Ссылка
я думаю, ошибка заключалась в том, что ты использовал префикс !, хотя команда tags была инициализирована как слэш команда.
я убрал command_prefix
и добавил некоторые разрешения для бота.
вот как выглядит мой код:
import disnake
from disnake.ext import commands
from disnake import TextInputStyle
intents = disnake.Intents.default()
intents.members = True
intents.reactions = True
intents.messages = True
intents.guilds = True
InteractionBot = commands.InteractionBot(intents=intents)
# Subclassing the modal.
class MyModal(disnake.ui.Modal):
def __init__(self):
# The details of the modal, and its components
components = [
disnake.ui.TextInput(
label="Name",
placeholder="Foo Tag",
custom_id="name",
style=TextInputStyle.short,
max_length=50,
),
disnake.ui.TextInput(
label="Description",
placeholder="Lorem ipsum dolor sit amet.",
custom_id="description",
style=TextInputStyle.paragraph,
),
]
super().__init__(title="Create Tag", components=components)
# The callback received when the user input is completed.
async def callback(self, inter: disnake.ModalInteraction):
embed = disnake.Embed(title="Tag Creation")
for key, value in inter.text_values.items():
embed.add_field(
name=key.capitalize(),
value=value[:1024],
inline=False,
)
await inter.response.send_message(embed=embed)
async def on_error(self, error: Exception, inter: disnake.ModalInteraction):
await inter.response.send_message(f"An error occurred!\n```{error}```")
@InteractionBot.slash_command()
async def tags(inter: disnake.AppCmdInter):
"""Sends a Modal to create a tag."""
await inter.response.send_modal(modal=MyModal())
InteractionBot.run("token")