#How to mention user who invite to a group

6 messages · Page 1 of 1 (latest)

elder surge
#

this is my code,
works to get the username, but doesn't work to mention the user who inviting to the group

i try just use @ but not work thoo...

client.on("group_join", async (notification) => {
  const inviters = await notification.getContact();
  const participant = notification.id.participant;

  await delay(timeer);
  try {
    console.log(inviters);

    if (notification.id.participant === participant) {
      notification.reply(
        "Hello @" +
          inviters.pushname +
          " :wave:" +
          "\nThx inviting me on this group:grin:"
      );
    }
  } catch (error) {
    console.error("Error:", error);
  }
});```
lament aspen
#

Try ```js
await notification.reply(
"Hello @" +
inviters.pushname +
" :wave: " +
"\nThx inviting me on this group:grin:", null, {mentions: [inviters]});

elder surge
# lament aspen Try ```js await notification.reply( "Hello @" + inviters.pushname + " :...

try code like this:

client.on("group_join", async (notification) => {
  const inviters = notification.getContact();
  const participant = notification.id.participant;

  await delay(timeer);
  try {
    if (notification.id.participant === participant) {
      await notification.reply(
        "Hello @" +
          inviters.pushname +
          " :wave:" +
          "\nThx inviting me on this group:grin:",
        null,
        { mentions: inviters }
      );
    }
  } catch (error) {
    console.error("Error:", error);
  }
});```

and got error like this:
```js
Error: TypeError: Cannot read properties of null (reading 'mentions')
    at Client.sendMessage (C:\xampp\htdocs\wangsap_bot\Wangsap-Bot\node_modules\whatsapp-web.js\src\Client.js:829:21)
    at GroupNotification.reply (C:\xampp\htdocs\wangsap_bot\Wangsap-Bot\node_modules\whatsapp-web.js\src\structures\GroupNotification.js:99:28)
    at Client.<anonymous> (C:\xampp\htdocs\wangsap_bot\Wangsap-Bot\index.js:101:26)```
elder surge
elder surge
#

i think i solve the problem, for now.
just like this:

client.on("group_join", async (notification) => {
  const inviters = await notification.getContact();
  const participant = notification.id.participant;

  try {
    const myNumb = "[email protected]";
    if (participant === myNumb) {
      const text = `Hello 👋\nThanks to @${inviters.id.user} for invite me on this group😀`;

      notification.reply(text, { mentions: [inviters.id._serialized] });
    }
  } catch (error) {
    console.error("[!] Error:", error);
  }
});