DemonDeparture
DIAdiscord.js - Imagine an app
•Created by DemonDeparture on 7/30/2023 in #djs-questions
How to convert code to js14?
Code is
// Import required modules
const { Client, Intents } = require('discord.js');
// Create a new client with necessary intents
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
// Replace 'YOUR_BOT_TOKEN' with your actual bot token
const BOT_TOKEN = 'MTEzNTE5NjU3NjM0ODkwOTYwOA.G-8KoH.bMI4RGNftDSQlD9J5J0aSW1eCOybnNiT4hvzkE';
// The ID of the channel where the bot will listen for messages
const TARGET_CHANNEL_ID = '1135196103537606697';
// When the bot is ready and connected to Discord
client.on('ready', () => {
console.log(Logged in as ${client.user.tag}!);
});
// Listen for messages
client.on('messageCreate', (message) => {
// Check if the message was sent in the target channel and not by the bot itself
if (message.channel.id === TARGET_CHANNEL_ID && !message.author.bot) {
// Create an embed message with the user's message content
const embed = new MessageEmbed()
.setColor('#ff0000')
.setDescription(message.content)
.addField('Radio', message.content)
.setFooter('Wagner Group CampBase Radio');
// Send the embed message
message.channel.send({ embeds: [embed] });
// Delete the user's original message
message.delete().catch((err) => console.error('Error deleting message:', err));
}
});
// Log in to Discord with your bot token
client.login(BOT_TOKEN);
8 replies