简体   繁体   中英

Javascript ~ How to send a message in a specific channel discord.js v13

As you know recently discord.js has moved to v13. I try to send a message in a specific channel but it gives me an error. Here's my code:

let channel = client.channels.cache.get(CHANNEL_ID)
channel.send(`${MSG}`)

This is my error:

TypeError: Cannot read property 'send' of undefined

Please help me. I've tried finding similar topics here and the only solution I found was in typescript but I want it in javascript.

使用client.guilds.cache.get("ID").channels.cache.get("ID").send()应该有帮助!

You could also use:

let channel = GUILD.channels.cache.get(CHANNEL_ID);
channel.send(MSG);

discord.js v13 needs you to specify which events you want your bot to receive. To achieve this you need to select, so called "Gateway Intents".

Here is a guide on Gateway Intents and how you configure them.
Here is a list of all Intents and what events they allow your bot to receive.

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