Ali
Ali
DIdiscord.js - Imagine ❄
Created by Ali on 12/15/2024 in #djs-questions
No discord user id mention in embed
So i've connected my bot into my FiveM server and when mentioning players on discord with there discordID in embed
const express = require('express');
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const bodyParser = require('body-parser');

const app = express();
const PORT = 3000;
const channelID = "1317635852104634388";

app.use(bodyParser.json());

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});

client.once('ready', () => {
console.log(`Bot connecté en tant que ${client.user.tag}`);
});

let activeMessages = {};

app.post('/service', async (req, res) => {
const { action, playerName, discordID, startTime, endTime, source } = req.body;
const channel = client.channels.cache.get(channelID);
if (!channel) return res.status(500).send("Canal Discord introuvable.");


if (action === "start") {
const embed = new EmbedBuilder()
.setColor(0xFFFFFF)
.setAuthor({ name:`<@${discordID}>` })
.addFields(
{ name: "Début de service", value: `\`\`\`${startTime}\`\`\``, inline: true },
{ name: "Fin de service", value: `\`\`\`-\`\`\``, inline: true }
);

const message = await channel.send({ embeds: [embed] });
activeMessages[source] = message.id;
res.send({ status: "Début de service enregistré." });

} else if (action === "end") {
const messageId = activeMessages[source];
if (messageId) {
const message = await channel.messages.fetch(messageId);
if (message) {
const updatedEmbed = EmbedBuilder.from(message.embeds[0])
.setColor(0xFFFFFF)
.spliceFields(1, 1, { name: "Fin de service", value: `\`\`\`${endTime}\`\`\``, inline: true });

await message.edit({ embeds: [updatedEmbed] });
delete activeMessages[source];
res.send({ status: "Fin de service enregistré." });
}
}
} else {
res.status(400).send("Action invalide.");
}
});

app.listen(PORT, () => {
console.log(`Serveur HTTP en écoute sur le port ${PORT}`);
});

client.login("
");


const express = require('express');
const { Client, GatewayIntentBits, EmbedBuilder } = require('discord.js');
const bodyParser = require('body-parser');

const app = express();
const PORT = 3000;
const channelID = "1317635852104634388";

app.use(bodyParser.json());

const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});

client.once('ready', () => {
console.log(`Bot connecté en tant que ${client.user.tag}`);
});

let activeMessages = {};

app.post('/service', async (req, res) => {
const { action, playerName, discordID, startTime, endTime, source } = req.body;
const channel = client.channels.cache.get(channelID);
if (!channel) return res.status(500).send("Canal Discord introuvable.");


if (action === "start") {
const embed = new EmbedBuilder()
.setColor(0xFFFFFF)
.setAuthor({ name:`<@${discordID}>` })
.addFields(
{ name: "Début de service", value: `\`\`\`${startTime}\`\`\``, inline: true },
{ name: "Fin de service", value: `\`\`\`-\`\`\``, inline: true }
);

const message = await channel.send({ embeds: [embed] });
activeMessages[source] = message.id;
res.send({ status: "Début de service enregistré." });

} else if (action === "end") {
const messageId = activeMessages[source];
if (messageId) {
const message = await channel.messages.fetch(messageId);
if (message) {
const updatedEmbed = EmbedBuilder.from(message.embeds[0])
.setColor(0xFFFFFF)
.spliceFields(1, 1, { name: "Fin de service", value: `\`\`\`${endTime}\`\`\``, inline: true });

await message.edit({ embeds: [updatedEmbed] });
delete activeMessages[source];
res.send({ status: "Fin de service enregistré." });
}
}
} else {
res.status(400).send("Action invalide.");
}
});

app.listen(PORT, () => {
console.log(`Serveur HTTP en écoute sur le port ${PORT}`);
});

client.login("
");


then it gives me something like this <@user_id> and not @user_id discord.js version = `-- [email protected] node version = v22.12.0
10 replies