Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with delete #15

Closed
V0idException opened this issue Oct 1, 2020 · 3 comments
Closed

Issue with delete #15

V0idException opened this issue Oct 1, 2020 · 3 comments
Labels
invalid This doesn't seem right

Comments

@V0idException
Copy link

V0idException commented Oct 1, 2020

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
Copy link
Owner

MalwareWerewolf commented Oct 2, 2020

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:

  • First the $deletemsg execution:
    First the $deletemsg execution

  • After the $deletemsg execution:
    Capture

@MalwareWerewolf MalwareWerewolf added bug Something isn't working invalid This doesn't seem right and removed bug Something isn't working labels Oct 2, 2020
@V0idException
Copy link
Author

V0idException commented Oct 3, 2020 via email

@MalwareWerewolf
Copy link
Owner

MalwareWerewolf commented Oct 4, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

2 participants