Home  >  Q&A  >  body text

How to send embedded message to bot and into server

<p>What I'm looking for is to embed the code I pass into the first available channel every time the bot enters the server. <br /><br />This will be a code snippet. </p><p><br /></p> <pre class="brush:php;toolbar:false;">const { Client, GatewayIntent`your text`Bits, MessageEmbed } = require('discord.js'); const config = require('./config.json'); const { EmbedBuilder } = require('discord.js'); const client = new Client({ intents: [ GatewayIntentBits.GuildMessages, GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences, GatewayIntentBits.MessageContent ] }); const prefix = config.prefix; client.on('ready', () => { console.log('Bot Ready'); }); client.on('messageCreate', message => { if (message.content === '!ping') { message.channel.send('pong'); } }); client.on('guildCreate', guild => { const channel = guild.channels.cache.find(channel => channel.type === 'text' && channel.permissionsFor(guild.me).has('SEND_MESSAGES')); if (channel) { const exampleEmbed = new MessageEmbed() .setColor(0xF99CF8) .setTitle('**B**') .setAuthor('S') .setThumbnail('https://i.imgur.com/N4') .setDescription('H') channel.send({ embeds: [exampleEmbed] }); } }); client.login(config.token);</pre> <p>Due to this code, the bot does not send any kind of message when entering the server, but starts normally. </p>
P粉127901279P粉127901279413 days ago483

reply all(1)I'll reply

  • P粉006847750

    P粉0068477502023-08-04 11:26:05

    If you are using discord.js v14, then you need to update the method of using embedded messages (Embeds) when replying to messages. Just change the code to the following:


    client.on('guildCreate', guild => {
    const channel = guild.channels.cache.find(channel => channel.type === 'text' && channel.permissionsFor(guild.me).has('SEND_MESSAGES'));
    if (channel) {
        const exampleEmbed = new EmbedBuilder()
            .setColor(0xF99CF8)
            .setTitle('**B**')
            .setAuthor('S')
            .setThumbnail('https://i.imgur.com/N4')
            .setDescription('H') 
        channel.send({ embeds: [exampleEmbed] });
    }});

    In addition, you need to modify the first line to:

    const { Client, GatewayIntentBits, EmbedBuilder} = require('discord.js');

    Just delete the third line to make your code clearer.

    For more details, visit here: https://discordjs.guide/popular-topics/embeds.html#embed-preview

    reply
    0
  • Cancelreply