can someon help me with a bot discord (discord.js node)
I created a discord bot in node, and for the ",ping" command it sends the same message 3 times... can it be solved? I can send the src, I have no problem with that!
11 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button![email protected] and v20.10.0
update
djs
ok
i have this problem
i need to ping one time and to contorize the pings..
in a few moments...
Well, can't you help me with the code? I can not handle it
i can update
[email protected]
done
ok, latest
done
require("dotenv").config();
const { Client, Collection, Intents } = require("discord.js");
const fs = require("fs");
const path = require("path");
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = ",";
const token = process.env.TOKEN;
if (!token || typeof token !== "string") {
throw new Error("TOKEN_INVALID: Tokenul furnizat este invalid.");
}
const pingCount = new Map();
const commandFiles = fs
.readdirSync(path.resolve("./src"))
.filter((file) => file.endsWith(".js"));
const commands = new Collection();
for (const file of commandFiles) {
try {
const command = require(path.resolve(`./src/${file}`));
commands.set(command.name, command);
} catch (error) {
console.error(`Eroare încărcare comandă: ${file}`, error);
}
}
client.once("ready", () => {
console.log("Botul este online!");
});
client.on("messageCreate", async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) {
if (message.channel.name.startsWith("slot-")) {
if (message.mentions.users.size > 0) {
const user = message.author;
let count = pingCount.get(user.id) || 0;
count++;
if (count > 1) {
message.channel.send(
`${user}, nu poți trimite ping-uri repetate! Canalul va fi șters.`
);
message.channel.delete();
return;
}
message.channel.send(`${user}, ${count}/1 ping-uri permise.`);
pingCount.set(user.id, count);
}
}
return;
}
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (commands.has(commandName)) {
const command = commands.get(commandName);
if (
command.requiresAdmin &&
!message.member.permissions.has("ADMINISTRATOR")
) {
message.reply("Doar administratorii pot folosi această comandă.");
return;
}
try {
command.execute(message, args);
} catch (error) {
console.error(error);
message.reply("A apărut o eroare în timpul execuției comenzii.");
}
}
if (message.content.startsWith(prefix + "ping")) {
if (!pingCount.has(message.author.id)) {
pingCount.set(message.author.id, 0);
}
let count = pingCount.get(message.author.id);
count++;
if (count > 1) {
message.channel.send(
`${message.author}, Ai folosit toate ping-urile posibile pentru astăzi. Cooldown de 24 de ore.`
);
message.channel.send(
`Nu puteți mai trimite ping-uri în acest canal pentru 24 de ore.`
);
message.channel.permissionOverwrites.edit(message.guild.roles.everyone, {
SEND_MESSAGES: false,
});
setTimeout(() => {
message.channel.permissionOverwrites.edit(message.guild.roles.everyone, {
SEND_MESSAGES: null,
});
}, 24 * 60 * 60 * 1000);
message.channel.send(
`ANNO! 🚨 Te rog să nu mai dai ping persoanelor. Vei pierde accesul slot-ului!`
);
return;
}
message.channel.send(`<@&1148177424647999529>`);
message.channel.send(`${count}/2 ping-uri folosite.`);
pingCount.set(count);
}
});
client.login(token);
require("dotenv").config();
const { Client, Collection, Intents } = require("discord.js");
const fs = require("fs");
const path = require("path");
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const prefix = ",";
const token = process.env.TOKEN;
if (!token || typeof token !== "string") {
throw new Error("TOKEN_INVALID: Tokenul furnizat este invalid.");
}
const pingCount = new Map();
const commandFiles = fs
.readdirSync(path.resolve("./src"))
.filter((file) => file.endsWith(".js"));
const commands = new Collection();
for (const file of commandFiles) {
try {
const command = require(path.resolve(`./src/${file}`));
commands.set(command.name, command);
} catch (error) {
console.error(`Eroare încărcare comandă: ${file}`, error);
}
}
client.once("ready", () => {
console.log("Botul este online!");
});
client.on("messageCreate", async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) {
if (message.channel.name.startsWith("slot-")) {
if (message.mentions.users.size > 0) {
const user = message.author;
let count = pingCount.get(user.id) || 0;
count++;
if (count > 1) {
message.channel.send(
`${user}, nu poți trimite ping-uri repetate! Canalul va fi șters.`
);
message.channel.delete();
return;
}
message.channel.send(`${user}, ${count}/1 ping-uri permise.`);
pingCount.set(user.id, count);
}
}
return;
}
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (commands.has(commandName)) {
const command = commands.get(commandName);
if (
command.requiresAdmin &&
!message.member.permissions.has("ADMINISTRATOR")
) {
message.reply("Doar administratorii pot folosi această comandă.");
return;
}
try {
command.execute(message, args);
} catch (error) {
console.error(error);
message.reply("A apărut o eroare în timpul execuției comenzii.");
}
}
if (message.content.startsWith(prefix + "ping")) {
if (!pingCount.has(message.author.id)) {
pingCount.set(message.author.id, 0);
}
let count = pingCount.get(message.author.id);
count++;
if (count > 1) {
message.channel.send(
`${message.author}, Ai folosit toate ping-urile posibile pentru astăzi. Cooldown de 24 de ore.`
);
message.channel.send(
`Nu puteți mai trimite ping-uri în acest canal pentru 24 de ore.`
);
message.channel.permissionOverwrites.edit(message.guild.roles.everyone, {
SEND_MESSAGES: false,
});
setTimeout(() => {
message.channel.permissionOverwrites.edit(message.guild.roles.everyone, {
SEND_MESSAGES: null,
});
}, 24 * 60 * 60 * 1000);
message.channel.send(
`ANNO! 🚨 Te rog să nu mai dai ping persoanelor. Vei pierde accesul slot-ului!`
);
return;
}
message.channel.send(`<@&1148177424647999529>`);
message.channel.send(`${count}/2 ping-uri folosite.`);
pingCount.set(count);
}
});
client.login(token);
updateOverwrite
method. In v13, the updateOverwrite
method was replaced by permissionOverwrites.edit.
require("dotenv").config();
const { Client, Collection, Intents } = require("discord.js");
const fs = require("fs");
const path = require("path");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
const prefix = ",";
const token = process.env.TOKEN;
if (!token || typeof token !== "string") {
throw new Error("TOKEN_INVALID: Tokenul furnizat este invalid.");
}
const pingCount = new Map();
const commandFiles = fs
.readdirSync(path.resolve("./src"))
.filter((file) => file.endsWith(".js"));
const commands = new Collection();
for (const file of commandFiles) {
try {
const command = require(path.resolve(`./src/${file}`));
commands.set(command.name, command);
} catch (error) {
console.error(`Eroare încărcare comandă: ${file}`, error);
}
}
client.once("ready", () => {
console.log("Botul este online!");
});
client.on("messageCreate", async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) {
if (message.channel.name.startsWith("slot-")) {
if (message.mentions.users.size > 0) {
const user = message.author;
let count = pingCount.get(user.id) || 0;
count++;
if (count > 1) {
message.channel.send(
`${user}, nu poți trimite ping-uri repetate! Canalul va fi șters.`
);
message.channel.delete();
return;
}
message.channel.send(`${user}, ${count}/1 ping-uri permise.`);
pingCount.set(user.id, count);
}
}
return;
}
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (commandName === "ping") {
if (!pingCount.has(message.author.id)) {
pingCount.set(message.author.id, 0);
}
let count = pingCount.get(message.author.id);
count++;
if (count > 2) {
message.channel.send(
`${message.author}, Ai folosit toate ping-urile posibile pentru astăzi. Cooldown de 24 de ore.`
);
message.channel.send(
`Nu puteți mai trimite ping-uri în acest canal pentru 24 de ore.`
);
message.channel.permissionOverwrites.edit(message.guild.roles.everyone, {
SEND_MESSAGES: false,
});
setTimeout(() => {
message.channel.permissionOverwrites.edit(
message.guild.roles.everyone,
{
SEND_MESSAGES: true,
}
);
}, 24 * 60 * 60 * 1000);
message.channel.send(
`ANNO! 🚨 Te rog să nu mai dai ping persoanelor. Vei pierde accesul slot-ului!`
);
return;
}
message.channel.send(`<@&1148177424647999529>`);
message.channel.send(`${count}/2 ping-uri folosite.`);
pingCount.set(message.author.id, count);
} else {
const command = commands.get(commandName);
if (!command) return;
try {
command.execute(message, args);
} catch (error) {
console.error(error);
message.reply("A apărut o eroare în timpul execuției comenzii.");
}
}
});
client.login(token);
require("dotenv").config();
const { Client, Collection, Intents } = require("discord.js");
const fs = require("fs");
const path = require("path");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
const prefix = ",";
const token = process.env.TOKEN;
if (!token || typeof token !== "string") {
throw new Error("TOKEN_INVALID: Tokenul furnizat este invalid.");
}
const pingCount = new Map();
const commandFiles = fs
.readdirSync(path.resolve("./src"))
.filter((file) => file.endsWith(".js"));
const commands = new Collection();
for (const file of commandFiles) {
try {
const command = require(path.resolve(`./src/${file}`));
commands.set(command.name, command);
} catch (error) {
console.error(`Eroare încărcare comandă: ${file}`, error);
}
}
client.once("ready", () => {
console.log("Botul este online!");
});
client.on("messageCreate", async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) {
if (message.channel.name.startsWith("slot-")) {
if (message.mentions.users.size > 0) {
const user = message.author;
let count = pingCount.get(user.id) || 0;
count++;
if (count > 1) {
message.channel.send(
`${user}, nu poți trimite ping-uri repetate! Canalul va fi șters.`
);
message.channel.delete();
return;
}
message.channel.send(`${user}, ${count}/1 ping-uri permise.`);
pingCount.set(user.id, count);
}
}
return;
}
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
if (commandName === "ping") {
if (!pingCount.has(message.author.id)) {
pingCount.set(message.author.id, 0);
}
let count = pingCount.get(message.author.id);
count++;
if (count > 2) {
message.channel.send(
`${message.author}, Ai folosit toate ping-urile posibile pentru astăzi. Cooldown de 24 de ore.`
);
message.channel.send(
`Nu puteți mai trimite ping-uri în acest canal pentru 24 de ore.`
);
message.channel.permissionOverwrites.edit(message.guild.roles.everyone, {
SEND_MESSAGES: false,
});
setTimeout(() => {
message.channel.permissionOverwrites.edit(
message.guild.roles.everyone,
{
SEND_MESSAGES: true,
}
);
}, 24 * 60 * 60 * 1000);
message.channel.send(
`ANNO! 🚨 Te rog să nu mai dai ping persoanelor. Vei pierde accesul slot-ului!`
);
return;
}
message.channel.send(`<@&1148177424647999529>`);
message.channel.send(`${count}/2 ping-uri folosite.`);
pingCount.set(message.author.id, count);
} else {
const command = commands.get(commandName);
if (!command) return;
try {
command.execute(message, args);
} catch (error) {
console.error(error);
message.reply("A apărut o eroare în timpul execuției comenzii.");
}
}
});
client.login(token);
const { Client, Intents } = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
const prefix = ",";
client.on("messageCreate", (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === "list") {
if (args.length < 2) {
return message.reply("Folosește comanda astfel: ,list <ID> <motiv>");
}
const userID = args[0];
const member = message.guild.members.cache.get(userID);
const username = member ? member.displayName : "Utilizator necunoscut";
const reason = args.slice(1).join(" ");
const messageContent = `${username} - ID: ${userID} - ${reason}`;
const channel = client.channels.cache.get("953052947879702621");
if (channel) {
channel.send(messageContent);
} else {
console.error("Canalul nu a fost găsit!");
}
}
});
client.login(process.env.TOKEN);
const { Client, Intents } = require("discord.js");
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
const prefix = ",";
client.on("messageCreate", (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift().toLowerCase();
if (command === "list") {
if (args.length < 2) {
return message.reply("Folosește comanda astfel: ,list <ID> <motiv>");
}
const userID = args[0];
const member = message.guild.members.cache.get(userID);
const username = member ? member.displayName : "Utilizator necunoscut";
const reason = args.slice(1).join(" ");
const messageContent = `${username} - ID: ${userID} - ${reason}`;
const channel = client.channels.cache.get("953052947879702621");
if (channel) {
channel.send(messageContent);
} else {
console.error("Canalul nu a fost găsit!");
}
}
});
client.login(process.env.TOKEN);