skip to Main Content

I look for the embed of the code that I have passed to be sent in the first available channel every time the bot enters a server.

This would be the code snippet.

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);

As a result of this code, the bot does not send any type of message when entering servers, but starts normally.

2

Answers


  1. if you are using discord.js v14 then you will need to update your way in replying with Embeds

    Just change to this code :

    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] });
    }});
    

    Also you will need to edit the first line to :

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

    just remove the third line to make your code cleaner

    For more details you can go here :
    https://discordjs.guide/popular-topics/embeds.html#embed-preview

    Login or Signup to reply.
  2. In discord.js v14,

    • MessageEmbed was renamed to EmbedBuilder along with other classes.
    • Channel types need to be checked via enums.
    • <Guild>.me was replaced by <Guild>.members.me.
    • Permission flags now follow PascalCase.
    const {
        ChannelType,
        Client,
        EmbedBuilder,
        GatewayIntentBits
    } = require('discord.js');
    
    client.on('guildCreate', guild => {
        const channel = guild.channels.cache.find(channel => channel.type === ChannelType.GuildText && channel.permissionsFor(guild.members.me).has('SendMessages'));
        if (channel) {
            const exampleEmbed = new EmbedBuilder()
                .setColor(0xF99CF8)
                .setTitle('**B**')
                .setAuthor('S')
                .setThumbnail('https://i.imgur.com/N4')
                .setDescription('H')
            channel.send({
                embeds: [exampleEmbed]
            });
        }
    });
    

    Read more about breaking changes in v14 here.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search