这是代码,
const Discord = require('discord.js')
const Keyv = require('keyv');
const client = new Discord.Client()
const prefixes = new Keyv();
const prefix = '/';
const eris = require('eris')
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`)
})
client.on('message',async message => {
if (message.author.bot) return;
let args;
// handle messages in a guild
if (message.guild) {
let prefix;
// if we found a prefix, setup args; otherwise, this isn't a command
if (!prefix) return;
args = message.content.slice(prefix.length).split(/ +/);
} else {
// handle DMs
const slice = message.content.startsWith(prefix) ? prefix.length : 0;
args = message.content.slice(slice).split(/ +/);
}
// get the first space-delimited argument after the prefix as the command
const command = args.shift().toLowerCase();
if (command === 'args-info') {
if (!args.length) {
return message.channel.send(`You didn't provide any arguments, ${message.author}!`);
}
message.channel.send(`Command name: ${command}\nArguments: ${args}`);
}
if (command === 'ping') {
return message.channel.send('Pong!')
}
if ( command === 'help'){
return message.channel.send('Sorry! I have no commands yet. You can use /ping to make me reply "Pong!"')
}
if(message === '(╯°□°)╯︵ ┻━┻'){
return message.channel.send('(╯°□°)╯︵ ┻━┻ yo face.')
}
if(message === '┬─┬ ノ( ゜-゜ノ)') return message.reply('thanks for returning the table.')
if(command === 'about') return message.channel.send('Creator: mudkip989, Version: 1.0.0, Name: ' + client.user.tag)
})
client.login(process.env.TOKEN)
我已经测试过并且机器人在线,并且我使用了有效的更简单的代码,但是当我有了这个时,它就不起作用了。我不明白为什么。我已经做出了更改,也许我需要了解更多“规则”或不和谐机器人代码不起作用的东西。
最佳答案
if (message.guild) {
let prefix;
// if we found a prefix, setup args; otherwise, this isn't a command
if (!prefix) return;
看起来您在这里所做的就是声明一个名为 prefix
的变量,然后检查它的值是否为假。由于 prefix
的值未定义,因此其计算结果始终为 true。
还需要指出的是,您的 let 前缀;
正在使用相同的名称隐藏您的全局常量。
关于javascript - 当我对此进行更改时,我的 Discord.js 机器人没有响应,我还是新人,但我看不出出了什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58083699/