The first thing you want to do is getting the channel
mentioned in the command args
and the mentioned user
:
const channelID = args[1];
const mentionedUser = message.mentions.members.first();
if(!channelID) return message.reply('You need to provide a channelID!');
if(!mentionedUser) return message.reply(`Please use a proper member mention!`);
const targetChannel = await message.client.channels.fetch(channelID);
In order to get the ID
of a channel
you have to activate developer mode
in your Discord, then you can right click the target channel
and hit Copy channel ID
Alternatively you should be able to get a channel
by it's name:
const targetChannel = guild.channels.cache.find(channel => channel.name === "Name of the channel");
After that is done you can now send your message to the destinated channel:
targetChannel.send(`Hello ${mentionedUser.toString()}`);
The reason why I'm using .toString()
is because message.mentions.members.first()
returns a GuildMember
. If you look at the docs you'll notice that .toString()
automatically returns the user's mention
instead of the GuildMember
object.