node.js - 如何让 Discord 机器人将消息发送到 Discord Node js 的特定频道机器人
问题描述
所以我希望我的不和谐机器人能够向某个频道发送消息,这样它就可以接受报告并做出回应,所以如果我这样做了 ;report {message} 它会将消息放入某个频道或 dm
解决方案
所以首先它非常简单,我将向您展示我的完整代码和您的语法
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')
这将允许您进行报告命令将此命令修改为您想要的任何内容并将其修改为您想要的内容。
推荐阅读
- excel - 如何解决 VBA 和 Powershell 之间的这种特殊字符编码问题?
- identity - 为身份服务器外部身份提供者请求添加中间端点
- wordpress - Woocommerce 产品出现在错误的类别中
- java - 双重检查锁定的声纳立方体错误
- amazon-web-services - 默认密码新 AWS 组织账户
- oracle-apex - 仅在调试模式下检索数据?
- python - 使用 QDataWidgetMapper 在 QTextBrowser 中显示纯文本
- swift - Swift 在另一个视图之上添加一个透明和模糊的视图
- java - 将子类转换为超类时抛出 java.lang.classCastException
- wpf - WPF CustomControl 可覆盖的默认样式