如何创建一个 JS Discord 机器人,将发送给它的任何文本中继到 Discord 服务器的通道中?
How do I create a JS Discord bot that relays whatever text is PMed to it into a channel of a discord server?
如标题所示,我想创建一个执行以下功能的 Discord Bot。
用户私信机器人,机器人会复制文本并将其与用户的不和谐名称一起粘贴到 Discord 服务器的文本通道中。这真的是我需要它做的所有事情,但我不知道如何对 Discord Bot 进行编程。
最好有人教我,但如果你把所有代码都给我,我只会试着阅读并自学。
谢谢!
只需安装 node.js 和 npm。
打开命令提示符并使用'CD /yourbotfolder'
使用 npm 安装 discord.js。 (npm install --save discord.js)
创建一个新的 Javascript 文件。
将此粘贴到其中:
const Discord = require('discord.js');
const bot = new Discord.Client();
var server;
var DChannel;
bot.on('ready', () => {
server = bot.guilds.get(YOUR_SERVER_ID);
DChannel = server.channels.get(YOUR_CHANNEL_ID);
console.log('--------------------\n\n\nREADY: '+ new Date() +'\n\n\n--------------------');
});
bot.on('message', (message)=>{
if (message.channel.type.toLowerCase() == 'dm' || message.channel.type.toLowerCase() == 'group') {
var embed = new Discord.RichEmbed()
.setAuthor(message.author.username, message.author.avatarURL)
.setDescription(message.content)
.setTimestamp(new Date())
.setColor('#C735D4');
DChannel.send(embed);
}
});
bot.login(process.env.TOKEN);
How to get a channel's id:
Right click on the channel, then click on 'Copy ID'
How to get your server's id:
Right click on your server's icon in your server list, then click on 'Copy ID'
现在打开命令提示符
再次输入 'CD /yourbotfolder',然后输入 运行:
node yourbotfile.js
如标题所示,我想创建一个执行以下功能的 Discord Bot。
用户私信机器人,机器人会复制文本并将其与用户的不和谐名称一起粘贴到 Discord 服务器的文本通道中。这真的是我需要它做的所有事情,但我不知道如何对 Discord Bot 进行编程。
最好有人教我,但如果你把所有代码都给我,我只会试着阅读并自学。
谢谢!
只需安装 node.js 和 npm。
打开命令提示符并使用'CD /yourbotfolder'
使用 npm 安装 discord.js。 (npm install --save discord.js)
创建一个新的 Javascript 文件。
将此粘贴到其中:
const Discord = require('discord.js');
const bot = new Discord.Client();
var server;
var DChannel;
bot.on('ready', () => {
server = bot.guilds.get(YOUR_SERVER_ID);
DChannel = server.channels.get(YOUR_CHANNEL_ID);
console.log('--------------------\n\n\nREADY: '+ new Date() +'\n\n\n--------------------');
});
bot.on('message', (message)=>{
if (message.channel.type.toLowerCase() == 'dm' || message.channel.type.toLowerCase() == 'group') {
var embed = new Discord.RichEmbed()
.setAuthor(message.author.username, message.author.avatarURL)
.setDescription(message.content)
.setTimestamp(new Date())
.setColor('#C735D4');
DChannel.send(embed);
}
});
bot.login(process.env.TOKEN);
How to get a channel's id: Right click on the channel, then click on 'Copy ID'
How to get your server's id: Right click on your server's icon in your server list, then click on 'Copy ID'
现在打开命令提示符
再次输入 'CD /yourbotfolder',然后输入 运行:
node yourbotfile.js