我不能让我的机器人回复我 我希望我的机器人在有人说嗨
时说你好吗答案 0 :(得分:1)
您可以使用每次发送消息时都会发出的message
event。
const Discord = require('discord.js');
const client = new Discord.Client();
client.on('message', (message) => {
console.log(message.content); // this is the content of the message
if (message.content === 'hi')
message.channel.send('How are you'); // send a message
});
我建议您阅读official discord.js
guide,以帮助您解决此类问题?
答案 1 :(得分:0)
您可以这样做:
const Discord = require('discord.js');
const bot = new Discord.Client();
bot.on('ready', () => {
console.log('\x1b[32m%s\x1b[0m', `${bot.user.username} is online on ${bot.guilds.cache.size} servers!`);
});
bot.on('message', (message) => {
if (message.content === 'hi') {
message.channel.send(`Hi ${message.author}`);
}
});
bot.login('TOKEN HERE');