bulkDelete method not working as intended
I am making a command that cleans chat, so you can remove spam, or unwanted chats etc. The command has worked fine one time and hasn't worked again, so I'm inclined to think it's something out of my control, but I don't know.
try {
let mod = message.guild.roles.find(role => role.name === "Mods");
if (!message.member.roles.has(mod.id)) return message.reply('You are not allowed to use this command.');
if (isNaN(args[0])) return message.reply("Please supply a number of messages to delete.");
if (args[0] > 100 || args[0] < 2) return message.reply('Please supply a number between 2 and 100 to delete.');
message.channel.bulkDelete(args[0] + 1);
} catch (err) {
console.log(err)
}
As said before, it's worked as intended one time, every other time, it just deletes hundreds of messages, for seemingly no reason. Maybe it is because I'm self-hosting for now and it's a latency issue? Not sure, either way, any help would be more than greatly appreciated. Thank you.
javascript node.js discord discord.js
add a comment |
I am making a command that cleans chat, so you can remove spam, or unwanted chats etc. The command has worked fine one time and hasn't worked again, so I'm inclined to think it's something out of my control, but I don't know.
try {
let mod = message.guild.roles.find(role => role.name === "Mods");
if (!message.member.roles.has(mod.id)) return message.reply('You are not allowed to use this command.');
if (isNaN(args[0])) return message.reply("Please supply a number of messages to delete.");
if (args[0] > 100 || args[0] < 2) return message.reply('Please supply a number between 2 and 100 to delete.');
message.channel.bulkDelete(args[0] + 1);
} catch (err) {
console.log(err)
}
As said before, it's worked as intended one time, every other time, it just deletes hundreds of messages, for seemingly no reason. Maybe it is because I'm self-hosting for now and it's a latency issue? Not sure, either way, any help would be more than greatly appreciated. Thank you.
javascript node.js discord discord.js
add a comment |
I am making a command that cleans chat, so you can remove spam, or unwanted chats etc. The command has worked fine one time and hasn't worked again, so I'm inclined to think it's something out of my control, but I don't know.
try {
let mod = message.guild.roles.find(role => role.name === "Mods");
if (!message.member.roles.has(mod.id)) return message.reply('You are not allowed to use this command.');
if (isNaN(args[0])) return message.reply("Please supply a number of messages to delete.");
if (args[0] > 100 || args[0] < 2) return message.reply('Please supply a number between 2 and 100 to delete.');
message.channel.bulkDelete(args[0] + 1);
} catch (err) {
console.log(err)
}
As said before, it's worked as intended one time, every other time, it just deletes hundreds of messages, for seemingly no reason. Maybe it is because I'm self-hosting for now and it's a latency issue? Not sure, either way, any help would be more than greatly appreciated. Thank you.
javascript node.js discord discord.js
I am making a command that cleans chat, so you can remove spam, or unwanted chats etc. The command has worked fine one time and hasn't worked again, so I'm inclined to think it's something out of my control, but I don't know.
try {
let mod = message.guild.roles.find(role => role.name === "Mods");
if (!message.member.roles.has(mod.id)) return message.reply('You are not allowed to use this command.');
if (isNaN(args[0])) return message.reply("Please supply a number of messages to delete.");
if (args[0] > 100 || args[0] < 2) return message.reply('Please supply a number between 2 and 100 to delete.');
message.channel.bulkDelete(args[0] + 1);
} catch (err) {
console.log(err)
}
As said before, it's worked as intended one time, every other time, it just deletes hundreds of messages, for seemingly no reason. Maybe it is because I'm self-hosting for now and it's a latency issue? Not sure, either way, any help would be more than greatly appreciated. Thank you.
javascript node.js discord discord.js
javascript node.js discord discord.js
edited Nov 19 '18 at 18:46


Federico Grandi
2,70021127
2,70021127
asked Nov 19 '18 at 18:27


Adam KerikAdam Kerik
5318
5318
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Unfortunately You've not read official manual about bulkDelete method
Otherwise You would know that it returns promise.
also keep in mind this:
Bulk delete given messages that are newer than two weeks.
This is only available when using a bot account.
So if Your account is bot account You can do it:
message.channel
.bulkDelete(args[0] + 1)
.then(messages => console.log(`Bulk deleted ${messages.size} messages`))
.catch(console.error);
So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
– Adam Kerik
Nov 19 '18 at 18:41
it does matter that You've to run that promise. Promise is special kind of class that has to be executed withthen
or usingasync/await
sugar
– num8er
Nov 19 '18 at 18:42
1
Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
– Adam Kerik
Nov 19 '18 at 18:45
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380609%2fbulkdelete-method-not-working-as-intended%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Unfortunately You've not read official manual about bulkDelete method
Otherwise You would know that it returns promise.
also keep in mind this:
Bulk delete given messages that are newer than two weeks.
This is only available when using a bot account.
So if Your account is bot account You can do it:
message.channel
.bulkDelete(args[0] + 1)
.then(messages => console.log(`Bulk deleted ${messages.size} messages`))
.catch(console.error);
So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
– Adam Kerik
Nov 19 '18 at 18:41
it does matter that You've to run that promise. Promise is special kind of class that has to be executed withthen
or usingasync/await
sugar
– num8er
Nov 19 '18 at 18:42
1
Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
– Adam Kerik
Nov 19 '18 at 18:45
add a comment |
Unfortunately You've not read official manual about bulkDelete method
Otherwise You would know that it returns promise.
also keep in mind this:
Bulk delete given messages that are newer than two weeks.
This is only available when using a bot account.
So if Your account is bot account You can do it:
message.channel
.bulkDelete(args[0] + 1)
.then(messages => console.log(`Bulk deleted ${messages.size} messages`))
.catch(console.error);
So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
– Adam Kerik
Nov 19 '18 at 18:41
it does matter that You've to run that promise. Promise is special kind of class that has to be executed withthen
or usingasync/await
sugar
– num8er
Nov 19 '18 at 18:42
1
Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
– Adam Kerik
Nov 19 '18 at 18:45
add a comment |
Unfortunately You've not read official manual about bulkDelete method
Otherwise You would know that it returns promise.
also keep in mind this:
Bulk delete given messages that are newer than two weeks.
This is only available when using a bot account.
So if Your account is bot account You can do it:
message.channel
.bulkDelete(args[0] + 1)
.then(messages => console.log(`Bulk deleted ${messages.size} messages`))
.catch(console.error);
Unfortunately You've not read official manual about bulkDelete method
Otherwise You would know that it returns promise.
also keep in mind this:
Bulk delete given messages that are newer than two weeks.
This is only available when using a bot account.
So if Your account is bot account You can do it:
message.channel
.bulkDelete(args[0] + 1)
.then(messages => console.log(`Bulk deleted ${messages.size} messages`))
.catch(console.error);
answered Nov 19 '18 at 18:36
num8ernum8er
11.4k21939
11.4k21939
So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
– Adam Kerik
Nov 19 '18 at 18:41
it does matter that You've to run that promise. Promise is special kind of class that has to be executed withthen
or usingasync/await
sugar
– num8er
Nov 19 '18 at 18:42
1
Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
– Adam Kerik
Nov 19 '18 at 18:45
add a comment |
So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
– Adam Kerik
Nov 19 '18 at 18:41
it does matter that You've to run that promise. Promise is special kind of class that has to be executed withthen
or usingasync/await
sugar
– num8er
Nov 19 '18 at 18:42
1
Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
– Adam Kerik
Nov 19 '18 at 18:45
So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
– Adam Kerik
Nov 19 '18 at 18:41
So, why exactly does it matter how I catch the error, when it is a promise, good answer, just curious.
– Adam Kerik
Nov 19 '18 at 18:41
it does matter that You've to run that promise. Promise is special kind of class that has to be executed with
then
or using async/await
sugar– num8er
Nov 19 '18 at 18:42
it does matter that You've to run that promise. Promise is special kind of class that has to be executed with
then
or using async/await
sugar– num8er
Nov 19 '18 at 18:42
1
1
Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
– Adam Kerik
Nov 19 '18 at 18:45
Cool, just was curious as to how that worked, will keep it in mind. Thank you, appreciate the answer.
– Adam Kerik
Nov 19 '18 at 18:45
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53380609%2fbulkdelete-method-not-working-as-intended%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown