我在使用discord.js V14时遇到以下错误:TypeError:无法读取未定义的属性(读取"send")
感谢所有能帮助我的人。
const { Client, Message, MessageEmbed } = require("discord.js");
const {SlashCommandBuilder} = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('test')
.setDescription('this is a test thing'),
/**
* @parom {Client} client
* @parom {Message} message
* @parom {String[]} args
*/
async execute(client, message, args, interaction) {
const questions = [
"test",
"test1?"
];
let collectCounter = 0;
let endCounter = 0;
const filter = (m) => m.author.id === message.author.id;
const author = message.author;
const appStart = await author.send(questions[collectCounter++]);
const channel = appStart.channel;
const collector = channel.createMessageCollector(filter);
message.delete({timeout: 100})
collector.on("collect", () => {
if (collectCounter < questions.length) {
channel.send(questions[collectCounter++]);
} else {
channel.send("submited!");
collector.stop("fulfilled");
}
});
const appsChannel = client.channels.cache.get("976110575547482152");
collector.on("end", (collected, reason) =>{
if (reason === "fulfilled") {
let index = 1;
const mappedResponses = collected
.map((msg) => {
return `${index++}) ${questions[endCounter++]}\n-> ${msg.content}`;
})
.join("\n\n");
appsChannel.send(
new MessageEmbed()
.setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true}))
.setTitle("!New Report!")
.setDescription(mappedResponses)
.setColor(`RANDOM`)
.setTimestamp()
);
appsChannel.send(`<@1057374161846145076>`);
}
});
},
};
注意我以前用过这个,一旦我更新到V14,我就开始得到这个错误。它应该向用户发送设置问题的消息,然后在一个通道中发布答案。
编辑:我在此行中遇到错误
const appStart = await author.send(questions[collectCounter++]);
我的interactions.js文件
module.exports = {
name: "interactionCreate",
async execute(interaction, client) {
if (interaction.isChatInputCommand()) {
const {commands} = client;
const {commandName} = interaction;
const command = commands.get(commandName);
if (!command) return;
try {
await command.execute(interaction, client);
} catch (error) {
console.error(error);
await interaction.reply({
content: `Something went wrong while executing this command...`,
ephemeral: true,
});
}
} else if (interaction.isButton()) {
const {buttons} = client;
const {customId} = interaction;
const button = buttons.get(customId);
if (!button) return new Error('This Button Does not exist');
try{
await button.execute(interaction, client);
} catch (err) {
console.error(err);
}
}
},
};
1条答案
按热度按时间qncylg1j1#
您正在使用
(interaction, client)
调用/test
命令文件的execute方法,但该方法需要(client, message, args, interaction)
。可能的解决方案是将
/test
命令文件更改为