MalwareWerewolf / RaptorSA

RaptorSA a multi function Discord Js bot.
MIT License
52 stars 53 forks source link

Issue with delete #15

Closed V0idException closed 3 years ago

V0idException commented 3 years ago

Hey, you had an issue with your delete command, you need to change it to

const deleteCount = parseInt(args[1], 10);

and all of this too.

` if (!message.member.hasPermission("MANAGE_MESSAGES")) { message.channel.send("You don't have the permissions to use this command!"); } else {

        if (isNaN(deleteCount) || deleteCount < 2 || deleteCount > 100) {
            return message.channel.send("Please provide a number between 2 and 100 for the number of messages to delete");
        } else {

            message.channel.bulkDelete(deleteCount).catch(error => message.reply(`Couldn't delete messages because of: ${error}`));

        }
    }
}`

Thanks!

MalwareWerewolf commented 3 years ago

Hello @Unseencow , could you describe what kind of bug you found in the code ?

The line where the constant deleteCount is declared, is correct. I tested your code but it does not work if you do not type a second parameter:

First test:

First Test

In the second test I typed $deletemsg 3 2 and the latest two messages (include the command for the bot) have been deleted.

Second Test

The array should start from 0 not 1.

The isNaN function is another possible implementation, but it does not change the code execution:

V0idException commented 3 years ago

Hello Cramenorn

Here is the code that worked for me

let args = message.content.substring(prefix.length).split(" ");

if (message.content.toLowerCase().startsWith(prefix + "clear")) {
    const deleteCount = parseInt(args[1], 10);
    if (!message.member.hasPermission("MANAGE_MESSAGES")) {
        message.channel.send(Embed64);
    } else {

        if (isNaN(deleteCount) || deleteCount < 1 || deleteCount > 100

) { return message.channel.send(Embed22); } else {

            message.channel.bulkDelete(deleteCount).catch(error =>

message.reply(Couldn't delete messages because of: ${error}));

Without the args[1] it just kept telling me to add a number,

also I added

isNaN(deleteCount)

instead of

!deleteCount

Why this you ask?

Well, considering the way I have the command written is this:

!clear 10

Meaning 10 messages get deleted, we pass that as the args, (prefix being arg 0, the number after being arg 1)

If I console.log the args, it returns this:

[image: image.png]

That's how mine worked, maybe your's is structured wrong, or I'm doing it wrong but this seemed to work for me

Thanks, Unseen

On Fri, 2 Oct 2020, 20:03 Davide Dolce, notifications@github.com wrote:

Closed #15 https://github.com/Cramenorn/RaptorSA/issues/15.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Cramenorn/RaptorSA/issues/15#event-3835274537, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQ2QHC5LMDXQPH6XIEBX3JDSIYPY5ANCNFSM4SA7MGDA .

MalwareWerewolf commented 3 years ago

Hello @Unseencow , maybe the problem is in another function where the args variable is initiliazed.

As I already said your solution is not the best, from the moment you force the user to input an additional parameter, which could be also confusing.

I also tested your solution and sometimes (the first one, I will talk about the second solution below), the command asked me to enter a number even if I entered the number correctly. That's why I said that your solution isn't the best, the problem could be in another function where the bot is initiliazed.

Capture

But if this is the case, the issue for this command should appear in other commands, not only in a single one.

There is no need to change the args declaration from const to let:

let args = message.content.substring(prefix.length).split(" ");

From the moment this variable is initialized one time when you execute a command and it does not change its value. It also appears to be wrong from the moment the command is not doing anything:

image

isNaN as I said is another solution but it does not change the code execution, you can still type a number without getting an error (if it's between 2 and 100 of course). If you type a string it returns an error message:

image

When you said:

Meaning 10 messages get deleted, we pass that as the args, (prefix being
arg 0, the number after being arg 1)

The prefix is not inside the args parameter, args includes every string separated by a space after the command, in other words a command like $deletemsg is not included in the args, for example:

$deletemsg firstargs secondargs etc.

I logged the args variable in message.js and this is what I get (there is no prefix in the array):

image

I also put a log in the deletemsg command to see the value of the args variable and this is what I get:

Args 2
Args 2
Args 6
Args 6
Args 3
Args sdfsdfdfsg

I do not get a value like [image: image.png], on the Discord.JS documentation, it specifies that the content property only accepts strings, in this case it can only accepts strings from the args parameter:

image

Where do you declare the variables Embed22 and Embed64 in the code ? What is their purpose ?

Your solutions add other functionalities which are not very useful and you are also doing more operations which are not necessary.

In conclusion, no modifications will be applied to the bot.