I am trying to make a discord bot send a message to a specific discord server using the server's id, I do not know the command for it, I tried something like this but it didn't work, thanks in advance! P.S I know the server and channel ids.
edit: updated the code as far as I got, now I get a error.
const Discord = require('discord.js');
const bot = new Discord.Client();
module.exports = {
name: "inviteme",
description: "inviteme",
execute(message, args){
var server = bot.guilds.get("642388927499730975");
var channel = server.channels.get("642389069829111809");
bot.guilds.forEach(guild => {
guild.channels.first().createInvite()
.then(inv => message(channel).send(`${guild.name} | ${inv.url}`));
});
}
}
The error I get is this:
TypeError: Cannot read property 'channels' of undefined
at Object.execute (d:\etc\Discord Bots\Coinflip\commands\inviteme.js:10:30)
at Client.<anonymous> (d:\etc\Discord Bots\Coinflip\index.js:31:42)
at Client.emit (events.js:210:5)
at MessageCreateHandler.handle (d:\etc\Discord Bots\Coinflip\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (d:\etc\Discord Bots\Coinflip\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:105:65)
at WebSocketConnection.onPacket (d:\etc\Discord Bots\Coinflip\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (d:\etc\Discord Bots\Coinflip\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:296:17)
at WebSocket.onMessage (d:\etc\Discord Bots\Coinflip\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:210:5)
at Receiver.receiverOnMessage (d:\etc\Discord Bots\Coinflip\node_modules\ws\lib\websocket.js:789:20)
Please help, thank you in advance.