@kutu33ov

Как сделать журнал удалённых сообщений от пользователей?

Хочу сделать журнал удалённых сообщений.

Вот код:
import discord
import asyncio
import os

class Deleted(discord.Client):
	def __init__(self, client):
		self.client = client

	

	async def on_message(self, message):
		if message.content.startswith('!editme'):
			msg = await message.channel.send('10')
			await asyncio.sleep(3.0)
			await msg.edit(content='40')

	async def on_message_edit(self, before, after):
		fmt = '**{0.author}** edited their message:\n{0.content} -> {1.content}'
		await before.channel.send(fmt.format(before, after))

def setup(client):
	client.add_cog(Deleted(client))
	print('Deleted: activated')


Ошибка:
Traceback (most recent call last):
  File "C:\Users\volva\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 618, in _load_from_module_spec
    setup(self)
  File "C:\Users\volva\Desktop\botTest\cogs\deleted.py", line 22, in setup
    client.add_cog(Deleted(client))
  File "C:\Users\volva\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 505, in add_cog
    raise TypeError('cogs must derive from Cog')
TypeError: cogs must derive from Cog

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

Traceback (most recent call last):
  File "C:\Users\volva\Desktop\botTest\bot.py", line 42, in <module>
    client.load_extension(f"cogs.{filename[:-3]}")
  File "C:\Users\volva\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 678, in load_extension
    self._load_from_module_spec(spec, name)
  File "C:\Users\volva\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 623, in _load_from_module_spec
    raise errors.ExtensionFailed(key, e) from e
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.deleted' raised an error: TypeError: cogs must derive from Cog
Press any key to continue . . .
  • Вопрос задан
  • 96 просмотров
Решения вопроса 1
SoreMix
@SoreMix Куратор тега Python
yellow
Смотрите примеры и читайте, что в ошибке написано. Кога должна наследоваться от Cog
https://discordpy.readthedocs.io/en/stable/ext/com...

class Deleted(commands.Cog):
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
11 мая 2024, в 00:19
1000 руб./за проект
10 мая 2024, в 23:51
30000 руб./за проект
10 мая 2024, в 23:33
2500 руб./за проект