你好,我是相当新的JavaScript,我试图让我的世界机器人,它记录聊天和发送都在聊天的不和谐频道说的消息。
const Discord = require('discord.js');
const Mineflayer = require('mineflayer');
const client = new Discord.client();
var bot = Mineflayer.createBot({
host: "localhost",
port: 62146,
email: "username",
password: "password",
});
bot.on('chat', function(username, message) {
if (username === bot.username) return;
channels.get("540620424426422272").send(message)
});
on("message", function(message) {
.channels.get()("500693869684326430").send(message)
});
client.login('token');
我认为你必须写
client.on("message"....)
并在从来自变量渠道?也许:
message.channels.get("540620424426422272").send(message)
你似乎在这里做多的事情,如果你只是想从我的世界将消息转发到不和谐通道,也没有必要以处理来自不和谐API发出的message
事件,只是Mineflayer发出的chat
事件。定义你的不和谐客户端时,你想要做的const client = Discord.Client();
不const client = Discord.client();
要小心。你不能只是做.channels.get()("500693869684326430").send(message)
在事件处理无论是。 camen6ert建议使用message.channels.get("540620424426422272").send(message)
作为一个可能的解决方案然而,随着你想,当你想获得一个特定的频道ID使用由Mineflayer,没有不和谐,发出该事件这是行不通的,我会建议使用client.channels.get('ID').send('Message content');
尝试这个:
const Discord = require('discord.js');
const Mineflayer = require('mineflayer');
const client = new Discord.Client();
var bot = Mineflayer.createBot({
host: "localhost",
port: 62146,
email: "username",
password: "password",
});
bot.on('chat', function(username, message) {
if (username === bot.username) return;
client.channels.get("540620424426422272").send(message)
});
client.login('token');