我寻找的是将我传递的代码嵌入到机器人每次进入服务器时的第一个可用频道中。
这将是代码片段。
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);
由于这段代码,机器人在进入服务器时不会发送任何类型的消息,而是正常启动。
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号