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

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

【问题讨论】:

标签: node.js discord discord.js


【解决方案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')

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

【讨论】:

  • 注意:此代码段不能在堆栈溢出内运行
  • 只有第一句和代码块与问题相关
猜你喜欢
  • 2021-06-17
  • 2020-12-18
  • 1970-01-01
  • 2020-10-25
  • 1970-01-01
  • 2021-04-09
  • 2020-12-23
  • 1970-01-01
  • 2022-11-02
相关资源
最近更新 更多