Milky4Skin
Milky4Skin

Reputation: 23

Is there an easy way to make my bot mention the person its moving?

so basically I wanted to make my bot move people to afk as soon as they deafen. and I have a command to make it generate messages in chat, but the question is, can I make it @ them as well? and if so how?

code:


const Discord = require("discord.js");

const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES", "GUILD_VOICE_STATES", "GUILD_MEMBERS", "GUILD_PRESENCES"] });



client.on("voiceStateUpdate", (oldState, newState) =>
{
    
    if (newState.selfDeaf)
    {
        console.log('User has deafened');
        newState.member.voice.setChannel("695840093167943751");
        client.channels.cache.get("664487959940169738").send('Undeafen Bitch');
    }

Upvotes: 0

Views: 56

Answers (1)

Rishi556
Rishi556

Reputation: 190

To tag a user in discord, the format is <@USERID> so if a user's id is 1, you'd have to include <@1> in what you are sending.

So onto your code, you'd have to change the last line to something like the following:

client.channels.cache.get("664487959940169738").send('<@123> Undeafen Bitch');

But we can't hardcode the id since it'll be unique for each user moved. This should automatically tag the user who got moved:

client.channels.cache.get("664487959940169738").send(`<@${newState.member.id}> Undeafen Bitch`);

Upvotes: 3

Related Questions