简体   繁体   中英

Discord.js V12 how can I remove a mentioned user from args?

I am trying to make a command for signing up, and usage is $signup <TeamName> @user . This command should give the user who executed the command and the @user (mentioned person) a "participant" role and it creates another role with the TeamName and gives it to them. And the max amount of people signing up is 32 teams (64 people in total). My current command is this, it doesn't have the create role "TeamName" thing because I don't really know how to do it.

client.on('message', async message => {
    if (message.content.startsWith(prefix + "signup")) {
        if (message.channel.id == '730099836451422331') {
    
let teamMate = message.mentions.members.first()    
const teamName = message.content.slice(prefix.length + 7).split(/  +/)
let testRole = message.guild.roles.cache.find(role => role.name == "Participant")
let testChannel = message.guild.channels.cache.find(channel => channel.name == "signup")
let guild = await message.guild.members.fetch();
let memberCount = testRole.members.size;

if(memberCount === 64) return message.channel.send("All spots have been filled. Thank you.")
if(!teamMate) return message.channel.send("Please mention your teammate! `$signup @user`")
if (message.member.roles.cache.some(role => role.name === 'Participant')) return message.channel.send("You already have the role.")
if (teamMate.roles.cache.some(role => role.name === 'Participant')) return message.channel.send("That teammate already has the role! Pick someone else!")
teamMate.roles.add(testRole)
message.member.roles.add(testRole)
message.guild.roles.create({data:{
    name: teamName
}})

Right now you have that ->

let teamMate = message.mentions.members.first()    
const teamName = message.content.slice(prefix.length + 7).split(/  +/)

You can change if for

const msgArr = message.content.split(' ');
const arg = msgArr.slice(number).filter(val => val !== '')
const teamName = arg.join(' ')

Where the number is the amount of args you want to remove for example you have signup user teamname so u need to remove 2 args and you will get the rest of the content as the anme of the team

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM