I
I
Ilya Zholudev2021-03-02 13:16:40
Node.js
Ilya Zholudev, 2021-03-02 13:16:40

How do I send a message to the first mentioned account?

Good day, my problem is that I can't send a message to the first mentioned channel. There is an example that works, here it is:

client.channels.cache.find(e=>e.name == "bugs")
        .send(embed).then( bug =>
            db.set(`${GetLastMID}`, {realid: `${bug.id}`, type: "bugs", channelid:`${message.channel.id}`, color: `${Color}`, title: `${dbTitle}`, bug: `${dbBug}`, 
            po: `${dbPO}`, launcher: `${dbLauncher}`, version: `${dbVersion}`, server: `${dbServer}`, url: `${dbUrl}`})
        );

Where it starts with db, it is a library for storing data in a local file (npm for short).
In the previous example, we used a channel with an already existing name.
And here:
const Mchannel = message.mentions.channels.first().name;


client.channels.cache.find(e=>e.name == `${Mchannel}`)
            .send(embed).then( repeat =>
            db.set(`${ID}`, {realid: `${repeat.id}`, type: "repeated", channelid:`${message.channel.id}`, rname:`${repeatname}`, rtext: `${textrepeat}`})
            );

I use the same approach but unfortunately it doesn't work for some reason. And gives an error:
TypeError: client.channels.cache.find(...).send is not a function

Can you help?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill, 2021-03-02
@Astroreen

If you want to use a specific channel, then instead of

const Mchannel = message.mentions.channels.first().name;
client.channels.cache.find(e=>e.name == `${Mchannel}`)
            .send(embed).then( repeat =>
            db.set(`${ID}`, {realid: `${repeat.id}`, type: "repeated", channelid:`${message.channel.id}`, rname:`${repeatname}`, rtext: `${textrepeat}`})
            );
use
const Mchannel = message.mentions.channels.first().id;
client.channels.cache.get(Mchannel)
            .send(embed).then( repeat =>
            db.set(`${ID}`, {realid: `${repeat.id}`, type: "repeated", channelid:`${message.channel.id}`, rname:`${repeatname}`, rtext: `${textrepeat}`})
            );

Use the documentation

A
AndromedaStar, 2021-03-02
@AndromedaStar

client.channels.cache.find(e=>e.name == `${Mchannel}`) - apparently returns undefined

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question