Answer the question
In order to leave comments, you need to log in
How can I make the bot ignore messages in a specific channel?
I'm making a bot that gives out a coin for a message in any channel. But I would like to make sure that he ignores messages from a certain channel and does not count them. it is made for one server.
here is the code:
const ACTIVITY = "In testing"
const API_TOKEN = "";
const Discord = require('discord.js');
const { Client, MessageEmbed } = require('discord.js');
const { RichEmbed } = require('discord.js');
const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
let coins = require("./coins.json");
let fs = require("fs");
const PREFIX = "!";
client.on('ready', async () => {
console.log(`Logged in as ${client.user.tag}`);
client.user.setStatus('idle');
client.user.setActivity(ACTIVITY, { type: "PLAYING"});
});
client.on('message', async message => {
if(!coins[message.author.id]){
coins[message.author.id] = {
coins: 0
};
}
let coinAmt = Math.floor(Math.random() * 1) + 1;
let baseAmt = Math.floor(Math.random() * 1) + 1;
if(coinAmt === baseAmt){
coins[message.author.id] = {
coins: coins[message.author.id].coins + coinAmt
};
fs.writeFile("./coins.json", JSON.stringify(coins), (err) => {
if (err) console.log(err)
});
}
let uCoins = coins[message.author.id].coins;
let coinEmbed = new MessageEmbed()
.setTitle(message.author.username)
.setColor("#00FF00")
.setDescription("Монеты:" + uCoins);
if(message.content === PREFIX + "coins")
{
message.channel.send(coinEmbed)
}
})
client.login(API_TOKEN);
Answer the question
In order to leave comments, you need to log in
some strange question, especially for a person who is able to write such code on his own.
if you are familiar with the operator if
, then I don't think it will be difficult for you to frame in if () a place that is responsible for issuing coins.
if you don't know how to get the channel ID -message.channel.id
if (ID_канала === "0000000") {
return;
} else {
// выдача
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question