如何使不和谐机器人将消息发送到不和谐 Node js 的特定频道机器人

Posted

技术标签:

【中文标题】如何使不和谐机器人将消息发送到不和谐 Node js 的特定频道机器人【英文标题】:How to make a discord bot send messages to a specific channel bot for discord Node js 【发布时间】:2021-08-14 00:33:32 【问题描述】:

所以我希望我的 discord 机器人能够将消息发送到某个频道,以便它可以接受报告并回复它们,所以如果我这样做;report message 它会将消息放入某个频道或 dm

【问题讨论】:

这能回答你的问题吗? How to send a message to a specific channel 【参考方案1】:

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

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

这将允许您制作一个报告命令,将此命令修改为您想要的任何内容,并将其修改为您希望的内容。

【讨论】:

注意:此代码段不能在堆栈溢出内运行 只有第一句和代码块与问题相关

以上是关于如何使不和谐机器人将消息发送到不和谐 Node js 的特定频道机器人的主要内容,如果未能解决你的问题,请参考以下文章

如何使不和谐的 js 机器人在某个时间在不和谐的确切文本通道中发送随机消息(我制作一个列表并发送它)

使不和谐机器人发送消息特定通道

将计算机信息发送到不和谐机器人

我需要帮助使不和谐卷曲

使用命令时如何使不和谐机器人更改脚本?

如何使不和谐机器人随机跳过响应