I
I
ItsRadic2022-02-15 22:02:12
Node.js
ItsRadic, 2022-02-15 22:02:12

How to send messages from the bot as a team to all participants who are on the server?

I just started learning JS language, and I want to know how to send a command message to all participants in private messages as embed? And is it even possible?
For example: "!message-all Hello! The bot has a global update!" etc.. and this was sent to all the participants in the discord server on which I wrote this message .

Please help, I've searched the entire internet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2022-02-15
@ItsRadic

message.guild.members.fetch().then(members => {
    members.filter(m => !m.user.bot).forEach(member => {
        member.send({
            embeds: [ваш_embed]
        }).catch(() => {
            console.log(`${member.user.tag} сообщение не было доставлено`)
        })
    })
})

For the code above to work, don't forget to add the GUILD_MEMBERS intent to the code:
const client = new Client({ intents: [...другие интенты, Intents.FLAGS.GUILD_MEMBERS] });

also, you must have the Server Members Intent item activated in the bot profile (Discord Developer Portal).
how to check if it is activated?
1) перейдите в Discord Developer Portal
2) выберите вашего бота
3) перейдите во вкладку "Bot"
4) пролистайте ниже и активируйте пункт "Server Members Intent"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question