[英]Discord.js v14 interaction failed
Receiving an error: this interaction failed, none of my console logs are outputting besides the "logged in as".收到错误:此交互失败,除了“登录为”外,我的控制台日志均未输出。 I have given the bot the correct token as well as permissions for admin, bot, and application.commands我已经为机器人提供了正确的令牌以及管理员、机器人和 application.commands 的权限
here is my index.js file这是我的 index.js 文件
const { Client, GatewayIntentBits, Events } = require('discord.js')
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
]
})
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
const options = [
'🐭',
'https://media.giphy.com/media/wJZTbXayokOgbCfyQe/giphy.gif',
'https://media.giphy.com/media/QXh9XnIJetPi0/giphy.gif',
'🐁',
];
client.on(Events.MessageCreate, message => {
console.log(message);
});
client.on(Events.InteractionCreate, interaction => {
console.log(`test1`);
if (!interaction.isCommand()) return;
console.log(`test3`);
if (interaction.commandName === 'hugging-face') {
console.log(`test3`);
interaction.reply(
options[Math.floor(Math.random() * options.length)]
);
}
});
client.login(process.env.TOKEN);
Here is my package.json这是我的 package.json
{
"name": "discord-slash-bot",
"version": "1.0.0",
"description": "package install",
"main": "index.js",
"scripts": {
"register": "node -r dotenv/config discord-slash-bot/register.js",
"start": "node -r dotenv/config index.js"
},
"keywords": [
"discord.js",
"@discordjs/rest",
"discord-api-types",
"dotenv"
],
"author": "conner",
"license": "ISC",
"dependencies": {
"@discordjs/rest": "^1.5.0",
"axios": "^1.2.3",
"discord-api-types": "^0.37.28",
"discord.js": "^14.7.1",
"dotenv": "^16.0.3"
}
}
Here is my register.js to register the commands这是我的 register.js 来注册命令
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const commands = [
{
name: 'hugging-face',
description: 'input images and prompt',
},
];
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(Routes.applicationCommands(process.env.APP_ID), {
body: commands,
});
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
I'm not exactly sure what the issue was, but it seems like register.js isn't running if there aren't any logs and/or was run before changes were made.我不确定问题出在哪里,但如果没有任何日志和/或在进行更改之前运行,register.js 似乎没有运行。 I would run:我会跑:
npm install && npm run register && npm run start
'npm install' would reinstall your dependencies, in case it's a versioning issue, while 'npm install' 会重新安装您的依赖项,以防出现版本控制问题,而
'npm run register' would run./discord-slash-bot/register.js to refresh all of the commands. 'npm run register' 将运行./discord-slash-bot/register.js 以刷新所有命令。
Hope this helps;希望这可以帮助; cheers!干杯!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.