When my bot joins a server, I am trying to makeit send a message to a channel in a specific guild, this is the code:
client.on('guildCreate', guild => {
guild.systemChannel.send('Thank you for adding Optic to your server. Run ``-help`` to view a full list of commands')
const server = client.guilds.cache.find(myserverId)
const channel = server.channels.cache.get(channelId)
const joinEmbed = new Discord.MessageEmbed()
.setTitle("Joined")
.setDescription("Optic was added to a server")
.addFields(
{ name: 'GuildId', value: guild.id,inline: false },
{ name: 'Name', value: guild.name, inline: false },
{ name: 'Guild OwnerId', value: guild.ownerID, inline: false },
)
channel.send(joinEmbed)
});
It then sends this error:
UnhandledPromiseRejectionWarning: TypeError: fn is not a function
at Map.find (/app/node_modules/@discordjs/collection/dist/index.js:161:17)
at Client.<anonymous> (/app/main.js:118:38)
at Client.emit (events.js:314:20)
at Object.module.exports [as GUILD_CREATE] (/app/node_modules/discord.js/src/client/websocket/handlers/GUILD_CREATE.js:33:14)
at WebSocketManager.handlePacket (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:31)
at WebSocketShard.onPacket (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
at WebSocketShard.onMessage (/app/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
at WebSocket.onMessage (/app/node_modules/ws/lib/event-target.js:132:16)
at WebSocket.emit (events.js:314:20)
at Receiver.receiverOnMessage (/app/node_modules/ws/lib/websocket.js:825:20)
(node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I checked the docs for it and I think I am using it correctly. I have also removed the guildId and channelId but they are in the actual code. Thanks