guild = ctx.guild
category = disnake.utils.get(guild.categories, name='RU-Тикеты')
if not category:
category = await guild.create_category(name='RU-Тикеты')
ticket_name = f'Запрос・{author_name}'
overwrites = {
guild.default_role: disnake.PermissionOverwrite(read_messages=False),
guild.get_member(author_id): disnake.PermissionOverwrite(read_messages=True)
}
ticket_channel = await category.create_text_channel(name=ticket_name, overwrites=overwrites)
message = await ticket_channel.send(
f'{user.mention}, Я слушаю Вас, гражданин! Опишите ваш вопрос, наши администраторы свяжутся с вами в ближайшее время.')
await asyncio.sleep(86400)
del ru_ticket_author[author_id]
await ticket_channel.delete()
User
Ignoring exception in on_button_click
Traceback (most recent call last):
File "C:\Users\daler\AppData\Local\Programs\Python\Python310\lib\site-packages\disnake\client.py", line 703, in _run_event
await coro(*args, **kwargs)
File "D:\SkyMP\bot\main.py", line 587, in on_button_click
await interaction.respond("Команда запрос вызвана", ephemeral=True)
AttributeError: 'MessageInteraction' object has no attribute 'respond'
Ignoring exception in command запрос:
Traceback (most recent call last):
File "C:\Users\daler\AppData\Local\Programs\Python\Python310\lib\site-packages\disnake\ext\commands\core.py", line 173, in wrapped
ret = await coro(*args, **kwargs)
File "D:\SkyMP\bot\main.py", line 543, in запрос
author_id = user.id
NameError: name 'user' is not defined
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\daler\AppData\Local\Programs\Python\Python310\lib\site-packages\disnake\ext\commands\bot_base.py", line 581, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\daler\AppData\Local\Programs\Python\Python310\lib\site-packages\disnake\ext\commands\core.py", line 912, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\daler\AppData\Local\Programs\Python\Python310\lib\site-packages\disnake\ext\commands\core.py", line 182, in wrapped
raise CommandInvokeError(exc) from exc
disnake.ext.commands.errors.CommandInvokeError: Command raised an exception: NameError: name 'user' is not defined
Assistant
Apologies for the errors. It seems that there are a couple of issues in the code. Here's the corrected version:
User
Ignoring exception in on_button_click
Traceback (most recent call last):
File "C:\Users\daler\AppData\Local\Programs\Python\Python310\lib\site-packages\disnake\client.py", line 703, in run_event
await coro(*args, **kwargs)
File "D:\SkyMP\bot\main.py", line 587, in on_button_click
await interaction.send("Команда запрос вызвана", ephemeral=True)
File "C:\Users\daler\AppData\Local\Programs\Python\Python310\lib\site-packages\disnake\interactions\base.py", line 695, in send
await sender(
File "C:\Users\daler\AppData\Local\Programs\Python\Python310\lib\site-packages\disnake\interactions\base.py", line 1023, in send_message
await adapter.create_interaction_response(
File "C:\Users\daler\AppData\Local\Programs\Python\Python310\lib\site-packages\disnake\webhook\async.py", line 210, in request
raise HTTPException(response, data)
disnake.errors.HTTPException: 400 Bad Request (error code: 40060): Interaction has already been acknowledged.
Assistant
My apologies once again. It seems that I overlooked the fact that once an interaction is acknowledged using interaction.respond or interaction.send, you cannot send multiple responses to the same interaction.
User
class DeleteMessageButton(Button):
def init(self):
super().init(style=ButtonStyle.red, label="Обращение", custom_id="delete_message")
guild = ctx.guild
category = disnake.utils.get(guild.categories, name='RU-Тикеты')
if not category:
category = await guild.create_category(name='RU-Тикеты')
ticket_name = f'Запрос・{author_name}'
overwrites = {
guild.default_role: disnake.PermissionOverwrite(read_messages=False),
ctx.author: disnake.PermissionOverwrite(read_messages=True)
}
ticket_channel = await category.create_text_channel(name=ticket_name, overwrites=overwrites)
message = await ticket_channel.send(
f'{ctx.author.mention}, Я слушаю Вас, гражданин! Опишите ваш вопрос, наши администраторы свяжутся с вами в ближайшее время.')
await asyncio.sleep(86400)
del ru_ticket_author[author_id]
await ticket_channel.delete()
Assistant
В коде, который вы предоставили, проблема возникает из-за того, что при создании канала тикета не указан автор. Чтобы исправить это, вам нужно изменить создание канала и установить автором канала пользовательский контекст вместо автора команды.
Вот обновленный код, который устанавливает автором канала пользователя, вызвавшего запрос через кнопку:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
In the запрос command, I have replaced user with ctx.author as the author of the command will be the user who invoked it.
In the обращение command and on_button_click event, I have changed interaction.respond to interaction.send as respond method is not available for MessageInteraction. Additionally, I have corrected the usage of interaction.send_message to interaction.send.
Please give it a try and let me know if you encounter any further issues.
To fix the issue, you can remove the line await interaction.send("Команда запрос вызвана", ephemeral=True) from the on_button_click event. Since the command запрос will already send a response in the ticket channel, there's no need for an additional response from the button interaction.