I'm adding some new things to a discord.js bot I made about a year ago. I have made a json file botconfigs.json
which looks like this:
{"641702354579881994":{"prefix":"$","modLogsChannel":643786173285924864}}
I have a file purge.js that deletes the messages in a channel and I want to send an embed to the channel specified in the JSON file. When I do console.log(botconfigs[guildid].modLogsChannel);
It prints out the channel id as it should. When I do bot.channels.get(botconfigs[guildid].modLogsChannel).send({embed: purgeEmbed});
it says:
Cannot read property 'send' of undefined
Full Code:
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).",
}
Originally I used bot.guilds.get('641702354579881994').channels.get('643786173285924864').send({embed: purgeEmbed});
and it worked perfectly. What am I doing wrong?
Thanks in advance!
Specifying a guild first might help ex:
bot.guilds.get(guildid)
.channels.get(botconfigs[guildid].modLogsChannel)
.send({embed: purgeEmbed});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.