Не подгружаются команды Disnake
У меня есть следующие файлы: основной (main.py
), директория с когами (cogs/...
) и конфиг (config.py
).
При запуске бота Discord всегда показывает, что "Интеграция не найдена", а в консоли пишет "Error 404: Unknown integration"
(но тогда пишет в Discord "Команда не отвечает".
Особенность кода:
- Подгружаются команды ТОЛЬКО с основного файла
- Команды с когов подгружаются, но не каждый раз (могут загрузиться, могут вообще не загружаться)
Код
import disnake
import rich
import json
import time
import datetime
import os
import random
import shutil
import sys
import config
import sqlite3
import cogs.then
from cogs.msg import Color, Icon
from disnake.ext import commands, tasks
from disnake import ui
from disnake.ext.commands import Context
from typing import Optional
from rich import *
from rich.console import Console
from rich.table import Table
from rich.progress import track
from rich.tree import Tree
from rich import print
bot = commands.InteractionBot(
intents = disnake.Intents.all(),
test_guilds = [тут ID моего сервера]
)
@bot.event
async def on_ready():
for extension in config.extensions:
extension = "cogs." + extension
try:
bot.load_extension(extension)
print(f"[bold green][ COG ][/bold green] Ког {extension} загружен")
except Exception as exc:
print(f"[bold red][ COG ][/bold red] Ког {extension} не удалось загрузить! ({exc.args})")
print(f"[bold green][ DONE ][/bold green] {bot.user.name} запущен!")
@bot.slash_command(name = "модуль")
@commands.is_owner()
async def modules(inter):
pass
@modules.sub_command(name = "загрузить", description = "Загрузить модуль бота")
@commands.is_owner()
async def module_load(
inter: disnake.CommandInteraction,
module: str = commands.Param(
name = "модуль",
description = "Название модуля",
choices = config.extensions
)
):
module_name = f"cogs.{module}"
try:
bot.load_extension(module_name)
message = disnake.Embed(
title = f"{Icon.success} Модуль загружен",
color = Color.Sucess,
timestamp = inter.created_at
).set_footer(text = f'Модуль {module}')
except:
message = disnake.Embed(
title = f"{Icon.error} Модуль не загружен",
color = Color.Error,
timestamp = inter.created_at
).set_footer(text = f'Модуль {module}')
await inter.response.send_message(embed = message)
@modules.sub_command(name = "выгрузить", description = "Выгрузить модуль бота")
@commands.is_owner()
async def module_unload(
inter: disnake.CommandInteraction,
module: str = commands.Param(
name = "модуль",
description = "Название модуля",
choices = config.extensions
)
):
module_name = f"cogs.{module}"
try:
bot.unload_extension(module_name)
message = disnake.Embed(
title = f"{Icon.success} Модуль выгружен",
color = Color.Sucess,
timestamp = inter.created_at
).set_footer(text = f'Модуль {module}')
except:
message = disnake.Embed(
title = f"{Icon.error} Модуль не выгружен",
color = Color.Error,
timestamp = inter.created_at
).set_footer(text = f'Модуль {module}')
await inter.response.send_message(embed = message)
@modules.sub_command(name = "перезагрузить", description = "Перезагрузить модуль бота")
@commands.is_owner()
async def module_reload(
inter: disnake.CommandInteraction,
module: str = commands.Param(
name = "модуль",
description = "Название модуля",
choices = config.extensions
)
):
module_name = f"cogs.{module}"
try:
bot.reload_extension(module_name)
message = disnake.Embed(
title = f"{Icon.success} Модуль перезагружен",
color = Color.Sucess,
timestamp = inter.created_at
).set_footer(text = f'Модуль {module}')
except:
message = disnake.Embed(
title = f"{Icon.error} Модуль не перезагружен",
color = Color.Error,
timestamp = inter.created_at
).set_footer(text = f'Модуль {module}')
await inter.response.send_message(embed = message)
bot.run(config.token)