Get multiple user

i want to do is only users that got pinged in that content can use the cmd otherwise you cant use it
25 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
grass
grass2y ago
what do you mean “content”
CoolName | Exam
CoolName | ExamOP2y ago
**:sparkles:Shiny Hunt Pings:** i want to make a autolock channel when there have sh hunter in poketwo
grass
grass2y ago
I still don’t understand what you mean you aren’t mentioning anyone in that
RRS Bunker
RRS Bunker2y ago
you can get all the pinged user id and save it in an array. and when someone is tyring to interact with the cmd, you can make the bot accepts inputs only from the ids that you collected and placed in the array
CoolName | Exam
CoolName | ExamOP2y ago
can you give me some codes example?
RRS Bunker
RRS Bunker2y ago
I'm not on my PC rn, but I can try to describe it. So first, use message.trim().split(/ /g) to turn received messages into array. Then you can use a loop/for and search each of the array and find every array index that has "<@" in it. Make sure to .slice(2) and .slice(-1) to get the user id only And then, filter out interaction from all user. Just do something like if (interaction.userID != [check each of the user id]) { (either do return; or tell the user it's not for them, and then return;)}
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2y ago
class MessageMentions Keeps track of mentions in a Message.
RRS Bunker
RRS Bunker2y ago
Seeing this, I should make a bot to make my server helping and guiding much easier :D Or if you're an expert in the shortcuts and not a slow poke who need to understand how the process works, you can do that too
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
RRS Bunker
RRS Bunker2y ago
(I'm roasting myself btw*) Good luck!
CoolName | Exam
CoolName | ExamOP2y ago
not understand at the loop/for part
RRS Bunker
RRS Bunker2y ago
alr so basically, you can get the mentions from what gwapes uwu said. and then for the loop part, its not quite like a loop. but the general idea is to check if the user id that replied matches any of the saved ids. Here's what i do to ignote imput from a set of channel (through their id):
const channelList = fs.readFileSync('./db/channelIgnore.txt', 'utf8');
var ChannelList = channelList.trim().split(/ +/g);
const MessageOriginChannelID = message.channelId


if (ChannelList.some(word => MessageOriginChannelID.startsWith(word))){
return;
}else{
...
const channelList = fs.readFileSync('./db/channelIgnore.txt', 'utf8');
var ChannelList = channelList.trim().split(/ +/g);
const MessageOriginChannelID = message.channelId


if (ChannelList.some(word => MessageOriginChannelID.startsWith(word))){
return;
}else{
...
maybe by implementing the same method (and use mentions instead of channel ID), you can do the same
CoolName | Exam
CoolName | ExamOP2y ago
mhm
RRS Bunker
RRS Bunker2y ago
also. it might be hard to see things, but I use different capitalizations for my channel variables and constant
RRS Bunker
RRS Bunker2y ago
in colored version
RRS Bunker
RRS Bunker2y ago
ignore the console log-
CoolName | Exam
CoolName | ExamOP2y ago
do you mean this?
function getUserFromMention(mention) {
if (!mention) return;

if (mention.startsWith('<@') && mention.endsWith('>')) {
mention = mention.slice(2, -1);

if (mention.startsWith('!')) {
mention = mention.slice(1);
}

return client.users.cache.get(mention);
}
}
function getUserFromMention(mention) {
if (!mention) return;

if (mention.startsWith('<@') && mention.endsWith('>')) {
mention = mention.slice(2, -1);

if (mention.startsWith('!')) {
mention = mention.slice(1);
}

return client.users.cache.get(mention);
}
}
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
CoolName | Exam
CoolName | ExamOP2y ago
so use message.mentions.user() ?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
RRS Bunker
RRS Bunker2y ago
Basically, just use message.mention.user.size to check how many mention is available in a message const mentionSize = message.mention.user.size; if (mentionSize < 1) return; //process the mention ids here @crow1000
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
RRS Bunker
RRS Bunker2y ago
oh. thx for telling me
Want results from more Discord servers?
Add your server