如何将嵌入式消息发送给机器人并进入服务器
P粉127901279
P粉127901279 2023-08-03 16:05:24
[JavaScript讨论组]

我寻找的是将我传递的代码嵌入到机器人每次进入服务器时的第一个可用频道中。

这将是代码片段。


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

由于这段代码,机器人在进入服务器时不会发送任何类型的消息,而是正常启动。

P粉127901279
P粉127901279

全部回复(0)
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号