#command?
1 messages · Page 1 of 1 (latest)
i want to know what i would have to do to store the number in the message as a variable to use later for the amount of messages to bulk delete
okay so
so
const args = message.content.slice(prefix.length).trim().split(/ +/);
you need this line for getting args
what it does is
message.content returns the message that was sent
so like if i were to send !hello
if (message.content.startsWith("H!clear ")){
}``` this is my code btw
it will return !hello
yup im running through the code so you can implement it yourself
if (!message.content.startsWith(prefix) || message.author.bot) return;
this line checks if the message
doesnt start with your prefix
or
is from a bot
mhm
and will return
so the commands dont get ran
const args = message.content.slice(prefix.length).trim().split(/ +/);
this line
what is does it
lets say
const prefix = "H!"
your prefix is this
yes it is
slices the message content?
it takes an integer as the argument
yes
it slices the front
so
lets say
let content = "H!command"
your content is this
if you do
mhm
content.slice(2)
it will take off
it will return "command"
yup
so i would do
ok so now
trim() just removes trailing spaces
.split() splits by space
so now
we have
H!clear 10
yes
args will return ["clear', "10"]
your command will be
args.shift()
which removes the first element and returns it
so
now we do
couldnt i just slice clear too?
that doesnt change the original array shift does
so now
wait no
slice will return an array
shift will return the element
which is a string
ok
so your command
if command === "clear" {}
to get the number
you do
const toClear = parseInt(args[1])
parseInt returns a number from a string
so now
ok
you want to get the messages
mhm
so you do
i do
wait
ok
lol
returns the MessageManager
couldnt you just do
?
channel.bulkDelete(n)
no
why not
lol
yaeh just do that
okily dokily
my bad ahah
message.channel.bulkDelete(toClear)
will clear x amount of messages from the channel that the command was sent in
yes
but to get the number, would i do this?
message.content.slice(prefix.length).trim().split(/ +/);
oh
yesp
no
you need to store the thing in a var
const Discord = require('discord.js');
const { prefix, token } = require('./config.json');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'ping') {
message.channel.send('Pong.');
} else if (command === 'beep') {
message.channel.send('Boop.');
}
// ...
});
client.login(token);
this is a good example
umm, how do i do that
read this, i gtg so sorry