Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
154 views
in Technique[技术] by (71.8m points)

node.js - im trying to create a ship command with a three members, its possible?, i tried to use the code below but dont works

I tried to use this code, but it doesn't work as I wanted, I have a ship code with only 2 members. and it works, I just wanted to know how I get the third mention of the message. its possible get the third mention?

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

    exports.run = async (client, message, args) => {
           
    let avatarbot = "https://cdn.discordapp.com/avatars/786665760273465425/153cb3d1933aeeb945e2a3b3b217fc36.png?size=1024;"
            
    let avatar = message.author.displayAvatarURL({format: 'png'})
              
 const embed0 = new Discord.MessageEmbed()
        .setTitle('Shipou!')
        .setColor('#000000')
        .setThumbnail(avatarbot)
        .setDescription("try to ship other members!")
        .setAuthor("Requested by " + message.author.tag, avatar)
                    
        if (!args[0]) return message.channel.send(embed0)
        if (!args[1]) return message.channel.send("you forgot to mention second user!")
        if (!args[2]) return message.channel.send("you forgot to mention third user!")
        if (args[0] || args[1] || args[2]) {
            var FirstUser = message.mentions.members.first() || message.guild.members.cache.get(args[0])
            var SecondUser = message.mentions.members.first(-1) || message.guild.members.cache.get(args[1])
            var ThirdUser = message.mentions.members.first(-2) || message.guild.members.cache.get(args[2])



            if (!FirstUser) return message.channel.send(`I couldn't find someone named **${args[0]}**!`)
            if (!SecondUser) return message.channel.send(`I couldn't find someone named **${args[1]}**!`)
            if (!ThirdUser) return message.channel.send(`I couldn't find someone named **${args[2]}**!`)
            
            
 
            if (FirstUser || SecondUser) {
                const FirstUserSliced = FirstUser.user.username.slice(0, FirstUser.user.username.length / 2)
                const SecondUserSliced = SecondUser.map(user => { return user.user.username.slice(user.user.username.length / 2) })
                const SecondUserName = SecondUser.map(user => { return user.user.username })
                const ThirdUserSliced = ThirdUser.map(user => { return user.user.username.slice(user.user.username.length / 2) })
                const ThirdUserName = ThirdUser.map(user => { return user.user.username })
 
 

      let user = message.mentions.users.first() || client.users.cache.get(args[0]);

      let avatar0 = user.displayAvatarURL({format: 'png'})


      
   
        const love = Math.random() * 100;
        const loveIndex = Math.floor(love / 10);
        const loveLevel = "??".repeat(loveIndex) + "??".repeat(10 - loveIndex);


              const embed1 = new Discord.MessageEmbed()
        .setTitle('Ship!')
        .setColor('#000000')
        .setThumbnail(avatar0)
        .setDescription("try to ship other members!")
        .addField(`?? ${Math.floor(love)}% ${loveLevel}`)
        .setAuthor("Requested by " + message.author.tag, avatar)

                message.channel.send(embed1)
            }
        }
}
     
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can check the message.mentions.members collection, then grab the first 3 by doing .first(3)

const mentions = message.mentions.members.first(3);

You can then check for the 3rd ([2]) element to verify that there are 3 total mentions

if (!mentions[2]) return // Your error message

Each individual mention is the individual element in the mentions array.

const firstMention = mentions[0];
const secondMention = mentions[1];
const thirdMention = mentions[2];

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...