Команды Discord Bot не развертываются (зависают при развертывании)Javascript

Форум по Javascript
Ответить Пред. темаСлед. тема
Anonymous
 Команды Discord Bot не развертываются (зависают при развертывании)

Сообщение Anonymous »

Мой бот Discord останавливается при развертывании команд для конкретной гильдии.
Он работал с тем же кодом, в том же месте, в той же гильдии, в том же терминале 3 минуты назад, и завис на развертывание сейчас. Однажды утром у меня возникла эта проблема, и она устранилась сама собой через много часов, когда мой Mac был отключен. Кто-нибудь понимает, в чем проблема?
Мой Deploy.js:
const { REST, Routes } = require('discord.js');
const { GlobalModules } = require('../config/modules');
const Guild = require('../models/Guild');
require('dotenv').config();

let clientCommands = null;

function setClientCommands(commands) {
clientCommands = commands;
}

async function clearCommands(guildId) {
const rest = new REST().setToken(process.env.TOKEN);

try {
console.log(`Lösche Commands für Guild ${guildId}...`);

// Prüfe globale Commands
console.log('Prüfe globale Commands...');
const globalCommands = await rest.get(
Routes.applicationCommands(process.env.CLIENT_ID)
);
console.log(
`Gefundene globale Commands: ${JSON.stringify(globalCommands, null, 2)}`
);

// Lösche globale Commands
for (const command of globalCommands) {
console.log(`Lösche globalen Command ${command.name} (${command.id})...`);
await rest.delete(
Routes.applicationCommand(process.env.CLIENT_ID, command.id)
);
}

// Prüfe guild-spezifische Commands
console.log('Prüfe guild-spezifische Commands...');
const guildCommands = await rest.get(
Routes.applicationGuildCommands(process.env.CLIENT_ID, guildId)
);
console.log(
`Gefundene Guild Commands: ${JSON.stringify(guildCommands, null, 2)}`
);

// Lösche guild-spezifische Commands
for (const command of guildCommands) {
console.log(`Lösche Guild Command ${command.name} (${command.id})...`);
await rest.delete(
Routes.applicationGuildCommand(
process.env.CLIENT_ID,
guildId,
command.id
)
);
}

console.log('Erfolgreich alle Commands gelöscht.');
} catch (error) {
console.error('Fehler beim Löschen der Commands:', error);
throw error;
}
}

async function deployCommandsForGuild(guildId) {
if (!clientCommands) {
console.error('Client commands wurden nicht initialisiert');
return;
}

const rest = new REST().setToken(process.env.TOKEN);
let guild = await Guild.findOne({ guildId });

// Wenn keine Konfiguration existiert, erstelle eine neue
if (!guild) {
try {
// Hole Guild-Informationen von Discord
const discordGuild = await rest.get(Routes.guild(guildId));
console.log(
`Erstelle neue Guild-Konfiguration für ${guildId} (${discordGuild.name})...`
);

guild = new Guild({
guildId,
name: discordGuild.name,
enabledModules: [],
availableModules: [],
});
await guild.save();
} catch (error) {
console.error(`Fehler beim Erstellen der Guild-Konfiguration: ${error}`);
return;
}
}

try {
// Erst alle Commands löschen
await clearCommands(guildId);

// Sammle alle Commands die deployed werden sollen
const commandsToRegister = [];

for (const [name, command] of clientCommands) {
// Wenn es ein globales Modul ist oder wenn das Modul aktiviert ist
if (
!command.module ||
GlobalModules.includes(command.module) ||
guild.enabledModules.includes(command.module)
) {
commandsToRegister.push(command.data.toJSON());
}
}

console.log(
`Starte Deployment von ${commandsToRegister.length} Commands für Guild ${guildId}...`
);

// Registriere die neuen Commands
await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT_ID, guildId),
{ body: commandsToRegister }
);

console.log(
`Erfolgreich ${commandsToRegister.length} Commands für Guild ${guildId} deployed.`
);
} catch (error) {
console.error('Fehler beim Deployen der Commands:', error);
}
}

module.exports = {
setClientCommands,
deployCommandsForGuild,
clearCommands,
};

И вывод:
✅ Erfolgreich mit MongoDB verbunden
🎉 Giveaway-System wird gestartet...
✅ Giveaway-System erfolgreich gestartet
Bereit! Eingeloggt als BayMax Dev#7945
Lösche Commands für Guild 1325228698642681928...
Prüfe globale Commands...
🕒 Reminder-System gestartet
Gefundene globale Commands: []
Prüfe guild-spezifische Commands...
Gefundene Guild Commands: []
Erfolgreich alle Commands gelöscht.
Lösche Commands für Guild 1325228698642681928...
Prüfe globale Commands...
Gefundene globale Commands: []
Prüfe guild-spezifische Commands...
Gefundene Guild Commands: []
Erfolgreich alle Commands gelöscht.
Starte Deployment von 2 Commands für Guild 1325228698642681928...


Подробнее здесь: https://stackoverflow.com/questions/793 ... -deploying
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Javascript»