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
d.js toolkit
d.js toolkit3mo ago
- 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!
! Tennessine [busy a few days]
discord.js@12.5.3 and v20.10.0
mallusrgreat
mallusrgreat3mo ago
update djs
! Tennessine [busy a few days]
i have this problem
No description
! Tennessine [busy a few days]
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 discord.js@13.0.0-dev.5af2ef5fbc7ad11281f38384c360ae79efe63b39 done
! Tennessine [busy a few days]
ok, latest done
d.js docs
d.js docs3mo ago
:guide: Additional Information: Updating from v12 to v13 read more :guide: Additional Information: Updating from v13 to v14 read more
! Tennessine [busy a few days]
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);
this is src and this is the problem and what can i do? done install We need to take into account the v13 changes in the 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);
it s ok now? I updated the code, but I see that a problem has been solved. but i have two now... the first problem is that it does not count pings. This means that 1/2 of the used pings are also written the second time. The second problem is that the ",list" command no longer works, which used to work before. Immediately you also receive "list.js"
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);
this is list.js Ok..