How to send embedded message to bot and into server
P粉127901279
P粉127901279 2023-08-03 16:05:24
0
1
482
<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粉127901279
P粉127901279

reply all(1)
P粉006847750

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!