You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

刷新Slash命令后Discord.js机器人无法启动且无报错(Replit环境)

Discord.js机器人在Replit中无法启动(无报错)

我基于discord.js官网示例代码开发机器人,在Replit环境执行Slash命令刷新操作后,机器人无法启动且没有任何报错信息。即使移除所有Slash命令相关代码,机器人仍然无法正常启动。

以下是替换令牌/ID后的代码:

const { REST, Routes, Client, GatewayIntentBits } = require('discord.js');

const commands = [
    {
        name: 'ping',
        description: 'Replies with Pong!',
    },
];

const rest = new REST({ version: '10' }).setToken(process.env.BOT_TOKEN);

(async () => {
    try {
        console.log('Started refreshing application (/) commands.');

        await rest.put(Routes.applicationCommands(process.env.BOT_ID), { body: commands });
    
        console.log('Successfully reloaded application (/) commands.');
    } catch (error) {
        console.error(error);
    }
})();

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.on('ready', () => {
    console.log(`Logged in as ${client.user.tag}!`);
});

client.on('interactionCreate', async interaction => {
    if (!interaction.isChatInputCommand()) return;

    if (interaction.commandName === 'ping') {
        await interaction.reply('Pong!');
    }
});

client.login(process.env.BOT_TOKEN);

控制台截图:
控制台截图

内容的提问来源于stack exchange,提问作者user15428862

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 23:15:36