DiscordJS 错误,在命令处理程序中嵌入消息
DiscordJS Error, Embed Message Within Command Handler
我试图让我的机器人使用嵌入消息,但它不起作用,因为我不断收到消息未定义错误
我试过只使用 author.bot 但后来出现了 Author not defined,有一点很重要,我正在使用 DiscordJS 指南提供的命令处理程序,然后我尝试使用 DiscordJS 指南对于 Embeds 但它没有用,这基本上就是我在这里结束的原因
下面的代码
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('embed')
.setDescription('A W.I.P Embed'),
async execute(interaction) {
const Embed1 = new MessageEmbed().setTitle('Some title');
if (message.author.bot) {
Embed1.setColor('#7289da');
}
}
};```
这是因为您在导出项目时使用了 message
对象:interaction
.
变化:
if (message.author.bot) {
Embed1.setColor('#7289da');
}
至:
if (interaction.user.bot) {
Embed1.setColor('#7289da');
}
没有 interaction.author
,只有 interaction.user
,因此这是检查它是否是机器人的唯一方法。
我试图让我的机器人使用嵌入消息,但它不起作用,因为我不断收到消息未定义错误
我试过只使用 author.bot 但后来出现了 Author not defined,有一点很重要,我正在使用 DiscordJS 指南提供的命令处理程序,然后我尝试使用 DiscordJS 指南对于 Embeds 但它没有用,这基本上就是我在这里结束的原因
下面的代码
const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('embed')
.setDescription('A W.I.P Embed'),
async execute(interaction) {
const Embed1 = new MessageEmbed().setTitle('Some title');
if (message.author.bot) {
Embed1.setColor('#7289da');
}
}
};```
这是因为您在导出项目时使用了 message
对象:interaction
.
变化:
if (message.author.bot) {
Embed1.setColor('#7289da');
}
至:
if (interaction.user.bot) {
Embed1.setColor('#7289da');
}
没有 interaction.author
,只有 interaction.user
,因此这是检查它是否是机器人的唯一方法。