-
Notifications
You must be signed in to change notification settings - Fork 53
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
Comments
Hello @Unseencow , 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: In the second test I typed $deletemsg 3 2 and the latest two messages (include the command for the bot) have been deleted. The array should start from 0 not 1. The isNaN function is another possible implementation, but it does not change the code execution: |
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, ***@***.***> wrote:
Closed #15 <#15>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#15 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AQ2QHC5LMDXQPH6XIEBX3JDSIYPY5ANCNFSM4SA7MGDA>
.
|
Hello @Unseencow , 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. 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:
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: 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: When you said:
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:
I logged the args variable in message.js and this is what I get (there is no prefix in the array): I also put a log in the deletemsg command to see the value of the args variable and this is what I get:
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: 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. |
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 {
Thanks!
The text was updated successfully, but these errors were encountered: