Trouble with Discord.py “purge” slash command. Unknown message error? (Follow-up response fails to send, causes error.)

I’m using discord.py, and one of my commands is “purge”. The problem being is that everytime I use the purge command, it deletes the amount of messages, but the “follow-up” response it is supposed to send causes an error. BE AWARE: This is a SLASH COMMAND.

(Please bear with me, I’m not entirely scripting this myself. I am still learning Python, so I use AI to help me script without sharing my token to it.)

Tried changing the code more than once, expected it to work normally and send “Purged {amount} messages”, but it shows up with “Unknown message” in the error.

Purge command:
`@tree.command(
name=”purge”,
description=”Deletes a specified number of messages from the channel.”
)
async def purge(interaction: Interaction, amount: int):
await interaction.response.defer() # Defers the interaction, giving you more time
try:
deleted = await interaction.channel.purge(limit=amount + 1) # +1 to account for the command message itself
await interaction.followup.send(f”Purged {len(deleted) – 1} messages.”) # Use followup to send the final response
except Exception as e:
await interaction.followup.send(f”An error occurred: {e}”)

@purge.error
async def purge_error(interaction: Interaction, error):
try:
if interaction.response.is_done():
await interaction.followup.send(“An error occurred while executing this command.”)
else:
if isinstance(error, commands.MissingPermissions):
await interaction.response.send_message(“You don’t have permission to use this command.”)
elif isinstance(error, commands.MissingRequiredArgument):
await interaction.response.send_message(“Please specify the number of messages to purge.”)
elif isinstance(error, commands.BadArgument):
await interaction.response.send_message(“Please provide a valid number.”)
else:
await interaction.response.send_message(“An error occurred while executing this command.”)
except Exception as e:
print(f”Failed to send error message: {e}”)`

Error Traceback:
`Task exception was never retrieved
future: <Task finished name=’CommandTree-invoker’ coro=<CommandTree._from_interaction..wrapper() done, defined at /usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/app_commands/tree.py:1107> exception=NotFound(‘404 Not Found (error code: 10008): Unknown Message’)>
Traceback (most recent call last):
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/app_commands/commands.py”, line 858, in do_call
return await self.callback(interaction, **params) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/psylar/Documents/PsylarBot/bot_commands.py”, line 26, in purge
await interaction.followup.send(f”Purged {len(deleted) – 1} messages.”) # Use followup to send the final response
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/webhook/async
.py”, line 1843, in send
data = await adapter.execute_webhook(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/webhook/async
.py”, line 221, in request
raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/app_commands/tree.py”, line 1268, in _call
await command._invoke_with_namespace(interaction, namespace)
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/app_commands/commands.py”, line 883, in _invoke_with_namespace
return await self._do_call(interaction, transformed_values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/app_commands/commands.py”, line 876, in _do_call
raise CommandInvokeError(self, e) from e
discord.app_commands.errors.CommandInvokeError: Command ‘purge’ raised an exception: NotFound: 404 Not Found (error code: 10008): Unknown Message

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/app_commands/tree.py”, line 1109, in wrapper
await self._call(interaction)
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/app_commands/tree.py”, line 1271, in _call
await command.invoke_error_handlers(interaction, e)
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/app_commands/commands.py”, line 802, in invoke_error_handlers
await self.on_error(interaction, error) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/home/psylar/Documents/PsylarBot/bot_commands.py”, line 31, in purge_error
await interaction.followup.send(“An error occurred while executing this command.”)
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/webhook/async
.py”, line 1843, in send
data = await adapter.execute_webhook(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/local/lib/python3.12/dist-packages/discord.py-2.4.0a5033+gf77ba711-py3.12.egg/discord/webhook/async
.py”, line 221, in request
raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message`

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật