应用系统



所以我为discord服务器制作了一个应用程序系统,在测试它时,机器人运行良好,直到应用程序的questiosn完成,它说应用程序已经发送,但它没有发送应用程序,我得到了一个错误,说

(node:11408) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'send' of undefined

这是我的代码错误在appsChannel.send(applicationembed);

const { Client, Message, MessageEmbed } = require('discord.js')
module.exports = {
name: "apply",
/**
* @param {Client} client
* @param {Message} message
* @param {string[]} args
*/
run: async (client, message, args) => {
const questions = [
"What is your IGN currently?",
"What is your discord Name and Tag?",
"Why do you want to join the guild?",
"What games stats are you applying with?",
"Is there anything else you want to tell us?"
];
let collectCounter = 0;
let endCounter = 0;
const filter = (m) => m.author.id === message.author.id;
const appStart = await message.author.send(questions[collectCounter++])
const channel = appStart.channel;
const collector = channel.createMessageCollector(filter);

collector.on("collect", () => {
if(collectCounter < questions.length) {
channel.send(questions[collectCounter++])
} else {
channel.send("You application has been sent!")
collector.stop("fulfilled")
}
})
const appsChannel = client.channels.cache.get('820355472635985991')
collector.on('end', (collected, reason) => {
if(reason === 'fulfilled') {
let index = 1;
const mappedResponses = collected.map((msg) => {
return `${index++}) ${questions[endCounter++]}n-> ${msg.content}`;
})
.join('nn');

const applicationembed = new MessageEmbed()
.setAuthor(
message.author.tag,
message.author.displayAvatarURL({ dynamic: ture })
)
.setTitle('New Application!')
.setDescription(mappedResponses)
.setColor('RANDOM')
.setTimestamp()
appsChannel.send(applicationembed);
}

})
},
}

您尝试获取的通道可能不在缓存中。获取总是最好的,而不是依赖于缓存。

将您的appsChannel定义更改为此。

const appsChannel = await client.channels.cache.fetch('820355472635985991');

你能在这里尝试使用await吗?

const appsChannel = await client.channels.cache.get('820355472635985991')

编辑:

const applicationembed = await new MessageEmbed()
.setAuthor(
message.author.tag,
message.author.displayAvatarURL({ dynamic: ture })
)
.setTitle('New Application!')
.setDescription(mappedResponses)
.setColor('RANDOM')
.setTimestamp()
await appsChannel.send(applicationembed);

让你的异步工作:

collector.on('end', async (collected, reason) => {

最新更新