[英]creating a help command for my discord bot
I am trying to create a help page that lists all the commands for my discord bot...我正在尝试创建一个帮助页面,列出我的 discord 机器人的所有命令...
currently everything is coming through as Undefined within the discord and I am confused as to why.目前,在 discord 中,一切都以未定义的形式出现,我对原因感到困惑。
Here is my help.js这是我的 help.js
const fs = require('fs');
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Lists all available commands'),
async execute(interaction) {
let str = '';
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./${file}`);
str += `Name: ${command.name}, Description: ${command.description} \n`;
}
return void interaction.reply({
content: str,
ephemeral: true,
});
},
};
I could try to do the v12 way, but I am trying to make a bot that is completely up to date with v13...我可以尝试使用 v12 方式,但我正在尝试制作一个与 v13 完全同步的机器人...
Assuming all of your commands are structured like the code you presented, you were only missing a couple things.假设您所有的命令都像您提供的代码一样结构化,那么您只遗漏了几件事。 First was that the command name and description would be under command.data
not just command
.首先是命令名称和描述将在command.data
下,而不仅仅是command
。 Also with let
you can leave it empty (as I have) and fill it with anything.也可以let
你把它留空(就像我一样)并用任何东西填充它。
const fs = require('fs');
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
data: new SlashCommandBuilder()
.setName('help')
.setDescription('Lists all available commands'),
async execute(interaction) {
let str
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./${file}`);
str += `Name: ${command.data.name}, Description: ${command.data.description} \n`;
}
return interaction.reply({
content: str,
ephemeral: true,
});
},
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.