简体   繁体   中英

Discord.JS Message in a specific Channel

So i'm new to the whole Discord.JS thing and i am trying to figure out how to get the bot to write a message to the General Chat when a new person joins.

I have seen a lot of people doing it like this:

const channel = client.channels.cache.find(channel => channel.name === channelName)
channel.send(message)

But this isnt working for me. Whenever i am trying to send a message with the channel.send(message) it gives me a error message.

I have also tried the version where you do it with the client.channels.cache.get(<Channel-ID>)

But this also didnt work for me.

Bro are you using discord.js v13 or 12 Tell that and if you are using v13 then

//If it is simple message
const channel = client.channels.cache.get('channel_id')
channel.send({ content: message })

//And if it is embed then
client.channels.cache.get('channel_id')
channel.send({ embeds: [message] })

// And if it is attachment
client.channels.cache.get('channel_id')
channel.send({ attachments: [message] })

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM