Discord.js无法读取未定义的属性“发送”

时间:2020-02-20 21:57:50

标签: javascript discord discord.js

我正在为大约一年前制作的discord.js机器人添加一些新功能。 我已经制作了一个看起来像这样的json文件botconfigs.json

{"641702354579881994":{"prefix":"$","modLogsChannel":643786173285924864}}

我有一个文件purge.js,该文件删除了通道中的消息,我想将嵌入内容发送到JSON文件中指定的通道。当我做console.log(botconfigs[guildid].modLogsChannel);时,它会按需打印出通道ID。当我做bot.channels.get(botconfigs[guildid].modLogsChannel).send({embed: purgeEmbed});时说:

无法读取未定义的属性“发送”

完整代码:

const Discord = require("discord.js");
const botconfigs = require("../botconfigs.json");

module.exports.run = async (bot, message, args) => {
    if(message.member.roles.some(r=>["Owner", "Co-Owner", "Manager", "Build Manager", "Development Manager", "Administrator", "Senior Builder", "Senior Developer", "Moderator+", "Builder+", "Developer+"].includes(r.name)) ) {
        const amount = args[0];
        if (!amount) return message.reply('You must specify an amount to delete! (Min: 2 Max: 100)');
        if (amount > 100) return message.reply('Specified amount too large! (Max: 100)');
        if (amount < 2) return message.reply('Specified amount too small! (Min: 2)');
        let guildid = message.guild.id;
        message.channel.fetchMessages({
        limit: 100,
        }).then((messages) => {
        message.channel.bulkDelete(amount).catch(error => console.log(error.stack));

        let purgeEmbed = new Discord.RichEmbed()
        .setColor("#00001")
        .setAuthor("HN Modlogs")
        .addField("Moderation:", "Purge", true)
        .addField("Messages Deleted:", amount, true)
        .setThumbnail(bot.user.displayAvatarURL)
        .addField("Moderator:", message.author.username, true)

        bot.channels.get(botconfigs[guildid].modLogsChannel).send({embed: purgeEmbed});
 });
  } else {
    return message.channel.send("You don't have permission to use this command!");
 }
}

module.exports.config = {
  name: "purge",
  usage: "u.purge <messageCount>",
  description: "Deletes Lots Of Messages (MAX 100).",
}

最初,我使用了bot.guilds.get('641702354579881994').channels.get('643786173285924864').send({embed: purgeEmbed});,它运行良好。我在做什么错了?

谢谢!

1 个答案:

答案 0 :(得分:0)

首先指定行会可能会有助于:

bot.guilds.get(guildid)
  .channels.get(botconfigs[guildid].modLogsChannel)
  .send({embed: purgeEmbed});