Jedi ThePro
Jedi ThePro

Reputation: 89

(Discord.js v12) Mention Arguments?

I tried to make a command with arguments and mentions. What I do is, I want to make mention the text channel as an argument. I might explain not quite good

Here's the example

For example, I added command with syntax: <prefix> <message> <#channel> but I can't mention channel in argument [2].

What I tried:

let msg = args[1];
let channel = message.mentions.channels.first(args[2]); // It quite not make any sense, right?

message.channel.send(`Message: ${msg} \nIn channel: ${channel}!`);

and it just crashes. A little help here!

Upvotes: 0

Views: 574

Answers (1)

LachlanDev
LachlanDev

Reputation: 355

The reason why it is crashing is because you are using "args[]" wrong, for let msg = args[1]; it should be set to args[0]. Now for the channel you can use args[1] or

You could try using message.mentions So you would do the following:

let channel = message.mentions.channels.first();

Complete Code:

let msg = args[0]; //Get the first word from the message
let announceChannel = message.mentions.channels.first(); //Get the announcement channel
message.channel.send(`Message: ${msg} \nIn channel: ${announceChannel}!`); //Let the sender know the announcement has been sent
announcementChannel.send(msg); //Send the announcement

Upvotes: 1

Related Questions