Whitelisting a channel for a command
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am in the progress of making a discord bot. This is one of the commands that auto-does itself.
What it is supposed to do it's if someone type .team buy 1
, save the data that comes out of another bot.
I would like to whitelist this command to 2 specific channels, identified by their channel id, and just ignore the message if it is not in the 2 channels.
How can I edit the code to do it?
const fs = require("fs");
module.exports.run = (client, message) => {
if ([509042284793430032, 501784044649054231].includes(message.channel.id)) return;
try {
//check if it's a different message //like when a user enters "team buy 234"
if (message.embeds[0].description.indexOf("❓") === 0) return;
//retrieve the team data
var teamData = JSON.parse(fs.readFileSync(client.config.dataFolder + "/teamUpgrades.json", "utf8"));
//get the current purchases data from the message
var arr = message.embeds[0].description.split("n");
//loop and save the data in "items" object
for (var i = 0; i < arr.length; i++) {
if (arr[i] == "") continue;
if (arr[i].indexOf("Unlocks") > -1) continue; //skip locked items
var opt = arr[i].split("|"); //item's info
var name = opt[0].trim();
if (name.indexOf("**") > -1)
name = name.substring(name.indexOf("**") + 2, name.length - 2).trim(); //bold
else
name = name.split(" ")[1]; //not bold
var price = opt[1].trim();
price = price.substring(3, price.length - 1);
price = parseInt(price.split(",").join(""));
var count = opt[2].trim();
count = parseInt(count.substring(1, count.length - 2).split(",").join(""));
var eps = opt[3].trim();
eps = parseFloat(eps.split(" ")[0].substring(1));
//if the item doesn't exist, create it
if (!teamData.items[name]) teamData.items[name] = {};
teamData.items[name].price = price;
teamData.items[name].eps = eps;
teamData.items[name].count = count;
}
//the best item to buy, let's give it a very high number first
var minItem = {
name: "",
min: Number.MAX_SAFE_INTEGER
};
for (var name in teamData.items) {
//The average price/eps
var average = Number(teamData.items[name].price) / Number(teamData.items[name].eps);
//if the current item is less than the minimum item, replace it.
if (average < minItem.min) {
minItem.name = name;
minItem.min = average;
}
}
//write the current data into the json file
fs.writeFileSync(client.config.dataFolder + "/teamUpgrades.json", JSON.stringify(teamData));
message.channel.send(minItem.name);
} catch (err) {
console.log(err);
}
}
javascript discord discord.js
add a comment |
I am in the progress of making a discord bot. This is one of the commands that auto-does itself.
What it is supposed to do it's if someone type .team buy 1
, save the data that comes out of another bot.
I would like to whitelist this command to 2 specific channels, identified by their channel id, and just ignore the message if it is not in the 2 channels.
How can I edit the code to do it?
const fs = require("fs");
module.exports.run = (client, message) => {
if ([509042284793430032, 501784044649054231].includes(message.channel.id)) return;
try {
//check if it's a different message //like when a user enters "team buy 234"
if (message.embeds[0].description.indexOf("❓") === 0) return;
//retrieve the team data
var teamData = JSON.parse(fs.readFileSync(client.config.dataFolder + "/teamUpgrades.json", "utf8"));
//get the current purchases data from the message
var arr = message.embeds[0].description.split("n");
//loop and save the data in "items" object
for (var i = 0; i < arr.length; i++) {
if (arr[i] == "") continue;
if (arr[i].indexOf("Unlocks") > -1) continue; //skip locked items
var opt = arr[i].split("|"); //item's info
var name = opt[0].trim();
if (name.indexOf("**") > -1)
name = name.substring(name.indexOf("**") + 2, name.length - 2).trim(); //bold
else
name = name.split(" ")[1]; //not bold
var price = opt[1].trim();
price = price.substring(3, price.length - 1);
price = parseInt(price.split(",").join(""));
var count = opt[2].trim();
count = parseInt(count.substring(1, count.length - 2).split(",").join(""));
var eps = opt[3].trim();
eps = parseFloat(eps.split(" ")[0].substring(1));
//if the item doesn't exist, create it
if (!teamData.items[name]) teamData.items[name] = {};
teamData.items[name].price = price;
teamData.items[name].eps = eps;
teamData.items[name].count = count;
}
//the best item to buy, let's give it a very high number first
var minItem = {
name: "",
min: Number.MAX_SAFE_INTEGER
};
for (var name in teamData.items) {
//The average price/eps
var average = Number(teamData.items[name].price) / Number(teamData.items[name].eps);
//if the current item is less than the minimum item, replace it.
if (average < minItem.min) {
minItem.name = name;
minItem.min = average;
}
}
//write the current data into the json file
fs.writeFileSync(client.config.dataFolder + "/teamUpgrades.json", JSON.stringify(teamData));
message.channel.send(minItem.name);
} catch (err) {
console.log(err);
}
}
javascript discord discord.js
add a comment |
I am in the progress of making a discord bot. This is one of the commands that auto-does itself.
What it is supposed to do it's if someone type .team buy 1
, save the data that comes out of another bot.
I would like to whitelist this command to 2 specific channels, identified by their channel id, and just ignore the message if it is not in the 2 channels.
How can I edit the code to do it?
const fs = require("fs");
module.exports.run = (client, message) => {
if ([509042284793430032, 501784044649054231].includes(message.channel.id)) return;
try {
//check if it's a different message //like when a user enters "team buy 234"
if (message.embeds[0].description.indexOf("❓") === 0) return;
//retrieve the team data
var teamData = JSON.parse(fs.readFileSync(client.config.dataFolder + "/teamUpgrades.json", "utf8"));
//get the current purchases data from the message
var arr = message.embeds[0].description.split("n");
//loop and save the data in "items" object
for (var i = 0; i < arr.length; i++) {
if (arr[i] == "") continue;
if (arr[i].indexOf("Unlocks") > -1) continue; //skip locked items
var opt = arr[i].split("|"); //item's info
var name = opt[0].trim();
if (name.indexOf("**") > -1)
name = name.substring(name.indexOf("**") + 2, name.length - 2).trim(); //bold
else
name = name.split(" ")[1]; //not bold
var price = opt[1].trim();
price = price.substring(3, price.length - 1);
price = parseInt(price.split(",").join(""));
var count = opt[2].trim();
count = parseInt(count.substring(1, count.length - 2).split(",").join(""));
var eps = opt[3].trim();
eps = parseFloat(eps.split(" ")[0].substring(1));
//if the item doesn't exist, create it
if (!teamData.items[name]) teamData.items[name] = {};
teamData.items[name].price = price;
teamData.items[name].eps = eps;
teamData.items[name].count = count;
}
//the best item to buy, let's give it a very high number first
var minItem = {
name: "",
min: Number.MAX_SAFE_INTEGER
};
for (var name in teamData.items) {
//The average price/eps
var average = Number(teamData.items[name].price) / Number(teamData.items[name].eps);
//if the current item is less than the minimum item, replace it.
if (average < minItem.min) {
minItem.name = name;
minItem.min = average;
}
}
//write the current data into the json file
fs.writeFileSync(client.config.dataFolder + "/teamUpgrades.json", JSON.stringify(teamData));
message.channel.send(minItem.name);
} catch (err) {
console.log(err);
}
}
javascript discord discord.js
I am in the progress of making a discord bot. This is one of the commands that auto-does itself.
What it is supposed to do it's if someone type .team buy 1
, save the data that comes out of another bot.
I would like to whitelist this command to 2 specific channels, identified by their channel id, and just ignore the message if it is not in the 2 channels.
How can I edit the code to do it?
const fs = require("fs");
module.exports.run = (client, message) => {
if ([509042284793430032, 501784044649054231].includes(message.channel.id)) return;
try {
//check if it's a different message //like when a user enters "team buy 234"
if (message.embeds[0].description.indexOf("❓") === 0) return;
//retrieve the team data
var teamData = JSON.parse(fs.readFileSync(client.config.dataFolder + "/teamUpgrades.json", "utf8"));
//get the current purchases data from the message
var arr = message.embeds[0].description.split("n");
//loop and save the data in "items" object
for (var i = 0; i < arr.length; i++) {
if (arr[i] == "") continue;
if (arr[i].indexOf("Unlocks") > -1) continue; //skip locked items
var opt = arr[i].split("|"); //item's info
var name = opt[0].trim();
if (name.indexOf("**") > -1)
name = name.substring(name.indexOf("**") + 2, name.length - 2).trim(); //bold
else
name = name.split(" ")[1]; //not bold
var price = opt[1].trim();
price = price.substring(3, price.length - 1);
price = parseInt(price.split(",").join(""));
var count = opt[2].trim();
count = parseInt(count.substring(1, count.length - 2).split(",").join(""));
var eps = opt[3].trim();
eps = parseFloat(eps.split(" ")[0].substring(1));
//if the item doesn't exist, create it
if (!teamData.items[name]) teamData.items[name] = {};
teamData.items[name].price = price;
teamData.items[name].eps = eps;
teamData.items[name].count = count;
}
//the best item to buy, let's give it a very high number first
var minItem = {
name: "",
min: Number.MAX_SAFE_INTEGER
};
for (var name in teamData.items) {
//The average price/eps
var average = Number(teamData.items[name].price) / Number(teamData.items[name].eps);
//if the current item is less than the minimum item, replace it.
if (average < minItem.min) {
minItem.name = name;
minItem.min = average;
}
}
//write the current data into the json file
fs.writeFileSync(client.config.dataFolder + "/teamUpgrades.json", JSON.stringify(teamData));
message.channel.send(minItem.name);
} catch (err) {
console.log(err);
}
}
javascript discord discord.js
javascript discord discord.js
edited Nov 19 '18 at 15:55
Federico Grandi
3,31331230
3,31331230
asked Nov 17 '18 at 0:57
Alpha1229Alpha1229
13
13
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
You can check if message.channel.id
is equal to one of your IDs and if not, ignore it.
module.exports.run = (client, message) => {
if (['ID 1 here', 'ID 2 here'].includes(message.channel.id)) return;
};
like this? it doesnt seem to work
– Alpha1229
Nov 19 '18 at 4:21
Nope: IDs are strings, but you wrote them as numbers. Use["509042284793430032", "501784044649054231"].includes(message.channel.id)
– Federico Grandi
Nov 19 '18 at 15:56
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%2f53347233%2fwhitelisting-a-channel-for-a-command%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
You can check if message.channel.id
is equal to one of your IDs and if not, ignore it.
module.exports.run = (client, message) => {
if (['ID 1 here', 'ID 2 here'].includes(message.channel.id)) return;
};
like this? it doesnt seem to work
– Alpha1229
Nov 19 '18 at 4:21
Nope: IDs are strings, but you wrote them as numbers. Use["509042284793430032", "501784044649054231"].includes(message.channel.id)
– Federico Grandi
Nov 19 '18 at 15:56
add a comment |
You can check if message.channel.id
is equal to one of your IDs and if not, ignore it.
module.exports.run = (client, message) => {
if (['ID 1 here', 'ID 2 here'].includes(message.channel.id)) return;
};
like this? it doesnt seem to work
– Alpha1229
Nov 19 '18 at 4:21
Nope: IDs are strings, but you wrote them as numbers. Use["509042284793430032", "501784044649054231"].includes(message.channel.id)
– Federico Grandi
Nov 19 '18 at 15:56
add a comment |
You can check if message.channel.id
is equal to one of your IDs and if not, ignore it.
module.exports.run = (client, message) => {
if (['ID 1 here', 'ID 2 here'].includes(message.channel.id)) return;
};
You can check if message.channel.id
is equal to one of your IDs and if not, ignore it.
module.exports.run = (client, message) => {
if (['ID 1 here', 'ID 2 here'].includes(message.channel.id)) return;
};
answered Nov 17 '18 at 17:22
Federico GrandiFederico Grandi
3,31331230
3,31331230
like this? it doesnt seem to work
– Alpha1229
Nov 19 '18 at 4:21
Nope: IDs are strings, but you wrote them as numbers. Use["509042284793430032", "501784044649054231"].includes(message.channel.id)
– Federico Grandi
Nov 19 '18 at 15:56
add a comment |
like this? it doesnt seem to work
– Alpha1229
Nov 19 '18 at 4:21
Nope: IDs are strings, but you wrote them as numbers. Use["509042284793430032", "501784044649054231"].includes(message.channel.id)
– Federico Grandi
Nov 19 '18 at 15:56
like this? it doesnt seem to work
– Alpha1229
Nov 19 '18 at 4:21
like this? it doesnt seem to work
– Alpha1229
Nov 19 '18 at 4:21
Nope: IDs are strings, but you wrote them as numbers. Use
["509042284793430032", "501784044649054231"].includes(message.channel.id)
– Federico Grandi
Nov 19 '18 at 15:56
Nope: IDs are strings, but you wrote them as numbers. Use
["509042284793430032", "501784044649054231"].includes(message.channel.id)
– Federico Grandi
Nov 19 '18 at 15:56
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.
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%2f53347233%2fwhitelisting-a-channel-for-a-command%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