【发布时间】:2021-03-27 15:51:05
【问题描述】:
这是我不断出错的代码:
const {
Message
} = require('discord.js');
const Discord = require('discord.js');
const Client = require('../client/Client');
module.exports = {
name: 'apply',
/**
* @param {Client} client
* @param {Message} message
* @param {String[]} args
*/
run: async (client, message, args) => {
message.channel.send('DM\'ing you, here is a reminder, you have to have DMs open for me to start and application process so remember to open DMs if they are closed.')
const questions = [`Would You Like To Apply?`, `This is a test correct?`, `am I friends with you`, `is this bot cool?`];
const f = new Discord.MessageEmbed()
.setTitle(`Hello would you answer some questions?`)
.setDescription(`I have seen you have sent the command a!apply in ${message.guild.name}.`)
const dmChannel = await message.author.send(f);
const collector = dmChannel.channel.createMessageCollector((msg) => msg.author.id == message.author.id);
let i = 0;
const res = [];
dmChannel.channel.send(questions[0])
collector.on('collect', async (msg) => {
if (questions.length == i) return collector.stop('MAX');
const answer = msg.content;
res.push({
question: questions[i],
answer
});
i++;
if (questions.length == i) return collector.stop('MAX');
else {
dmChannel.channel.send(questions[i]);
}
});
collector.on('end', async (collected, reason) => {
if (reason == 'MAX') {
const data = message.guild.channels.cache.find(ch => ch.name.toLowerCase() == 'app-logs' && ch.type == 'text');
const embed = new Discord.MessageEmbed()
.setTitle(`New Application`)
.setDescription(`**from** <@${message.author.id}>`)
.setColor('RANDOM')
const e = new Discord.MessageEmbed()
.setTitle(`Questions and Answers:`)
.setDescription(`${res.map(d => `**${d.question} - Answer:** ${d.answer}`).join("\n")}`, '\n ^^^^')
.setColor('RANDOM')
dmChannel.channel.send('Your application has been recorded thanks!')
// trying to code this
if (!data) {
message.guild.channels.create('app-logs', {
type: 'text',
permissionOverwrites: [{
id: message.guild.id,
deny: ['VIEW_CHANNEL'],
},
{
id: message.author.id,
deny: ['VIEW_CHANNEL'],
},
{
id: client.user.id,
allow: ['VIEW_CHANNEL'],
},
],
})
await data.send(embed)
await data.send(e)
}
await data.send(embed)
await data.send(e)
console.log(`${res.map(d => `${d.question} - ${d.answer}`).join("\n")}`)
console.log(`this is an application by from @${message.author.tag} in the guild (${message.guild.name})`)
}
})
}
}
错误是:
0|索引 | TypeError:无法读取未定义的属性“发送”
我正在尝试了解此错误的来源以及原因?
【问题讨论】:
标签: node.js discord.js