我正在研究一个不和谐机器人(这只是AI模块,还有另一个连接到同一个机器人的命令和东西),但它不知道它自己的
const token = process.env.PixelBot_token;
const keep_alive = require('./keep_alive.js');
const sendReply = require('./sendReply.js');
const Discord = require('discord.js');
const client = new Discord.Client();
// Set the client user's presence
client.on('ready', () => {
var prefix = client.user.tag;
console.log('PixelBot AI Loaded!');
console.log(prefix);
});
client.on('message', message => {
if (message.author.bot) return;
var prefix = + client.user.tag;
console.log(prefix);
if (message.content.substring(0, prefix.length) === prefix) {
//useful variables
const args = message.content.slice(prefix.length).trim().split(/ +/g);
const command = args.shift().toLowerCase();
if (command === "help") {
console.info("Help Message Sent!\n");
};
};
});
client.login(token);
上面的代码打印出来:
PixelBot AI Loaded!
PixelBot#9188
但是当我发送@PixelBot帮助时什么都不做。但是,如果我将前缀更改为字符串,例如:“pb”,则可以。它显然在“client.on('ready')”中知道它,因为它被打印出来。有任何想法吗?
编辑:以下是@Discord Expert建议的代码:
const token = process.env.PixelBot_token;
const keep_alive = require('./keep_alive.js');
const sendReply = require('./sendReply.js');
const Discord = require('discord.js');
const client = new Discord.Client();
// Set the client user's presence
client.on('ready', () => {
console.log('PixelBot AI Loaded!');
});
client.on('message', message => {
if (message.author.bot) return;
if (message.mentions.users.first() === client.user) {
//useful variables
const command = message.content.slice(message.mentions.users.first().length).trim().split(/ +/g);
const identifier = command.shift().toLowerCase();
console.log('identifier = "' + identifier + '"');
console.log('command = "' + command +'"');
console.log('message content = "' + message.content + '"');
打印出:
PixelBot AI Loaded!
identifier = "<@569971848322744320>"
command = "help"
message content = "<@569971848322744320> help"
所以它知道命令===“help”,为什么它不执行if语句?
繁花不似锦
相关分类