#to send a message in a specific channel
90 messages · Page 1 of 1 (latest)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- 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!
const channelId = '1183311645724917810'; // Remplace par l'ID de ton canal
try {
const channel = (channelId);
if (channel.isText()) {
channel.send('Salut à toi ! Ceci est un message envoyé depuis une commande slash.');
message.reply('Message envoyé dans le canal spécifié !');
} else {
message.reply('Le canal spécifié n\'est pas un canal textuel.');
}
} catch (error) {
console.log('Erreur lors de l\'envoi du message :', error);
}
error : Cannot send empty message
- const channel = (channelId);
- channel.send('ne marche pas');
+ const channel = client.channels.cache.get(channelId);
+ channel.send('marche');
Oh the channel type check is different in v14 btw
ok
-channel.isText()
+channel.type === ChannelType.GuildText
ChannelType is imported from djs
It's weird that this didn't sent any errors 
Non
yes
Did you check is the channel invalid or is the id correct? 
Waiting 
Erreur lors de l'envoi du message : ReferenceError: client is not defined
at Object.execute (E:\Areo bot\commands\ping.js:85:29)
at Client.<anonymous> (E:\Areo bot\index.js:64:17)
at Client.emit (node:events:531:35)
at MessageCreateAction.handle (E:\Areo bot\node_modules\discord.js\src\client\actions\MessageCreate.js:28:14)
at module.exports [as MESSAGE_CREATE] (E:\Areo bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (E:\Areo bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (E:\Areo bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (E:\Areo bot\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
at WebSocketShard.<anonymous> (E:\Areo bot\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (E:\Areo bot\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
Oh what did you define as the client?
The bot client
change the client with interaction.client
Or what you named your interaction
In the code snippet i sent
noo
Erreur lors de l'envoi du message : ReferenceError: client is not defined
at Object.execute (E:\Areo bot\commands\ping.js:85:29)
at Client.<anonymous> (E:\Areo bot\index.js:64:17)
at Client.emit (node:events:531:35)
at MessageCreateAction.handle (E:\Areo bot\node_modules\discord.js\src\client\actions\MessageCreate.js:28:14)
at module.exports [as MESSAGE_CREATE] (E:\Areo bot\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)
at WebSocketManager.handlePacket (E:\Areo bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (E:\Areo bot\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (E:\Areo bot\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
at WebSocketShard.<anonymous> (E:\Areo bot\node_modules\@discordjs\ws\dist\index.js:1173:51)
at WebSocketShard.emit (E:\Areo bot\node_modules\@vladfrangu\async_event_emitter\dist\index.js:282:31)
as been saved
Yeah because client isn't defined
You need the client, which is available via <interaction>.client and interaction being what you defined your interaction in the handler
The error spawns at ping.js 
all index.js ??
just the commands handler part
I do not have any 😅
then how do you access all commands in the commands folder?
hmm
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}```
how ur interactionCreate event looks like
euh ?
mb, i just read the issue, use this in your ping command
I don't think I have one either
Just show ping.js
euh
const { interactionclient, EmbedBuilder} = require('discord.js');
module.exports = {
name: 'ping',
description: 'Affiche la latence du bot Discord sous forme d\'embed.',
execute(message, args) {
const ping = Date.now() - message.createdTimestamp;
const memoryUsage = process.memoryUsage().heapUsed / 1024 / 1024;
const roundedMemory = Math.round(memoryUsage * 100) / 100;
let roundedping;
if (ping < 0) {
roundedping = Math.round(ping * -1);
} else {
roundedping = ping;
}
const guildId = message.guild.id;
const guildname = message.guild.name;
const username = message.author.username;
const userid = message.author.id;
const log = `Commande !ping executer en ${roundedping}ms dans (${guildId} ${guildname}) par ${userid} ${username}`
console.log(log);
if (roundedping < 1) {
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(':ping_pong: Pong! :1872dndweb:' )
.setDescription(`La latence du bot est de ${roundedping}ms`)
.addFields(
{ name: 'Ram', value: `${roundedMemory}MB`, inline: false}
)
.setTimestamp();
message.reply({ content: ' ', embeds: [embed] })
.catch(console.error);
} else if (roundedping >= 1 && roundedping < 500) {
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(':ping_pong: Pong! :3832_status_online:' )
.setDescription(`La latence du bot est de ${roundedping}ms`)
.addFields(
{ name: 'Ram', value: `${roundedMemory}MB`, inline: false}
)
.setTimestamp();
message.reply({ content: ' ', embeds: [embed] })
.catch(console.error);
} else if (roundedping >= 500 && roundedping < 1000) {
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(':ping_pong: Pong! :6708_status_idle: ' )
.setDescription(`La latence du bot est de ${roundedping}ms`)
.addFields(
{ name: 'Ram', value: `${roundedMemory}MB`, inline: false}
)
.setTimestamp();
message.reply({ content: ' ', embeds: [embed] })
.catch(console.error);
} else {
const embed = new EmbedBuilder()
.setColor('#0099ff')
.setTitle(':ping_pong: Pong! :2267_status_dnd: ' )
.setDescription(`La latence du bot est de ${roundedping}ms`)
.addFields(
{ name: 'Ram', value: `${roundedMemory}MB`, inline: false}
)
.setTimestamp();
message.reply({ content: ' ', embeds: [embed] })
.catch(console.error);
}
const channelId = '1183311645724917810'; // Remplace par l'ID de ton canal
try {
const channel = client.channels.cache.get(channelId);
if (channel.type === 'GUILD_TEXT') {
channel.send('f');
message.reply('Message envoyé dans le canal spécifié !');
} else {
message.reply('Le canal spécifié n\'est pas un canal textuel.');
}
} catch (error) {
console.log('Erreur lors de l\'envoi du message :', error);
}
},
};
const channel = message.client.channels.get(...)
Erreur lors de l'envoi du message : TypeError: message.client.channels.get is not a function

message.client.channels.cache.get()
Oh woops
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined
- All
SCREAMING_SNAKE_CASEenums have been changed toPascalCase - Intents:
Intents.FLAGS.GUILD_MESSAGES->GatewayIntentBits.GuildMessages - Permissions:
Permissions.FLAGS.SEND_MESSAGES->PermissionFlagsBits.SendMessages
remove "GUILD_TEXT" and use ChannelType.GuildText
Waiting again 
ok
Hu
Erreur lors de l'envoi du message : ReferenceError: ChannelType is not defined
alors
hmm
De rien
🙂
isTextBased() exists in v14
I saw isText() being deprecated and the guide suggesting to use enums. I didn't know it just had a rename 
Will keep in mind
They were removed in 14.0.0 and reintroduced in 14.0.1 or so
Aah i didn't update to that yet
Wha… you mean you‘re still on 14.0.0? That’s deprecated