How to send embedded message to bot and into server
P粉127901279
2023-08-03 16:05:24
<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>
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:
In addition, you need to modify the first line to:
Just delete the third line to make your code clearer.
For more details, visit here: https://discordjs.guide/popular-topics/embeds.html#embed-preview