首页 > 解决方案 > 如何让 Discord 机器人将消息发送到 Discord Node js 的特定频道机器人

问题描述

所以我希望我的不和谐机器人能够向某个频道发送消息,这样它就可以接受报告并做出回应,所以如果我这样做了 ;report {message} 它会将消息放入某个频道或 dm

标签: node.jsdiscorddiscord.js

解决方案


所以首先它非常简单,我将向您展示我的完整代码和您的语法

const channel = client.channels.cache.get('CHANNEL ID HERE')
channel.send('MESSAGE OR VARIABLE')

虽然为了运行它,您需要导入 discord js,所以我现在将向您展示我的完整机器人

const Discord = require('discord.js');
const client = new Discord.Client();
client.on("disconnected", function () {
    // alert the console
    console.log("Disconnected!");

    // exit node.js with an error
    process.exit(1);
});
client.on('ready', async () => {
    console.log('Bot is ready');
    client.user.setActivity('Blood Samurai', { type: 'STREAMING', url: 'https://www.youtube.com/watch?v=hOyfFPwas_A&t=324s' });
})
/** Direct Message Command */  
client.on('message', msg => { // Message function
    if (msg.author.bot) return; // Ignore all bots
    //Report Command
    if (msg.content.startsWith(";report ")) { // When a player does '!report'
        if (msg.content.slice(8) === '') return
        const help = msg.content.slice(8)
        const url = msg.author.avatarURL
        const exampleEmbed = new Discord.MessageEmbed()
            .setColor('#de0000')
            .setTitle('Oktan`s Report System')
            .setDescription('```lua\n--[TYPE]--\nServer reports\n--[DESCRIPTION]--\nServer reports deal with Moderation, request and assistance.\n--[SENDER]--\n' +msg.author.tag+ '\n--[REPORT INFORMATION]--\n' + help + '```')
          .setFooter('Please report random and usless reports to an admin -Server Staff Team','https://www.pinclipart.com/picdir/middle/74-746204_open-disclaimer-png-clipart.png',)
          const channel = client.channels.cache.get('ID HERE')
          channel.send(exampleEmbed);
        msg.channel.send('Your message will be moderated soon.')
      }
 });
client.login('TOKEN HERE')

这将允许您进行报告命令将此命令修改为您想要的任何内容并将其修改为您想要的内容。


推荐阅读