Script:
const Discord = require(‘discord.js’);
module.exports =
{
name: ‘Warn’,
description: Warn people use 'space' to give reason
,
cooldown: “3”,
run: async(message,args) =>
{
//args is Argument without prefix and command
const sender = message.member
if (sender.hasPermission(‘KICK_MEMBERS’))
{
const member = message.mentions.members.first();
var Embed = new Discord.MessageEmbed()
.setDescription(${member} was warned for ${args.join(' ').split(
&{member}).join(' ')}
)
.setColor(’#56F99C’)
message.channel.send(Embed)
}
},
};
I want to remove the 1st argument from args which is table
Sorry but i had to blur the name due to some reason
You can remove the first argument from args (an array) by using .shift()
.
args.shift();
Ok i will try it right now
I manipulated the code a bit
const member = message.mentions.members.first();
var Embed = new Discord.MessageEmbed()
.setDescription(`${member} was warned for ${args.shift().join(' ')}`)
.setColor('#56F99C')
message.channel.send(Embed)
TypeError: args.shift(…).join is not a function
Did i miss something?
For .shift()
to work, args
must be an array.
Here is args
args = message.content.split(’.${Command}’)
//this works^
I just want to remove the 1st argument
Can you do console.log(args);
and paste the result here?
Ok i will do it right now
Here is what it printed
[ ‘<@536467985783848971>’, ‘Testing’ ]
So you don’t want the first argument (which is the user’s mention), right?
Yes what i am trying to do is remove the user mention and the rest is the reason for warn so i just want to remove the mentioned name
Sorry if this was already answered but you should just be able to do args.slice(0).join(' ');
Can you do console.log(args);
right at the start of the run function and tell us what it logs actually?
We were trying to do
args.shift().join(’ ')
Try this:
const Discord = require(‘discord.js’);
module.exports =
{
name: ‘Warn’,
description: Warn people use ',' to give reason
,
cooldown: “3”,
run: async(message, args) =>
{
console.log(args);
const sender = message.member
if (sender.hasPermission(‘KICK_MEMBERS’))
{
const member = message.mentions.members.first();
var Embed = new Discord.MessageEmbed()
.setDescription(${member} was warned for ${args.slice(0).join(' ')}
)
.setColor(’#56F99C’)
message.channel.send(Embed)
}
},
};
It still pings the user in reason
Can you show us what the bot logs though?
It logs all the things:
User mention Testing if this works or not
all sperate by comma
I have already sent this also you can see it above as well
I think that was from console.log(args.shift().join(' '));
though - I’m asking for you to me the updated version of this from console.log(args);
Oh yes correct sorry
Output:
<@536467985783848971> Testing if this works or not
Code:
const member = message.mentions.members.first();
var Embed = new Discord.MessageEmbed()
.setDescription(${member} was warned for ${args.slice(0).join(' ')}
)
.setColor(’#56F99C’)
console.log(args.slice(0).join(’ '));
message.channel.send(Embed)
So console.log(args);
logs the text below into the Glitch project logs?
yes it logs it
<@536467985783848971> Testing if this works or not
Is that in an array?
I just want to remove the 1st argument is there any other way like
message.content.slice(${member}
)
Can you try this to get a string of everything past the first argument: args.slice(1).join(' ');
And if you just want an array of everything past the first argument: args.slice(1);
I think the first argument might be the bot prefix
No it’s not actually
const args = message.content.slice(prefix.length).split(' ');
Then args.slice(0).join(' ');
should work fine
I think that it also has space maybe that’s why it’s happening
It worked thanks very much