Javascript 当我对此进行更改时,我的discord.js bot没有响应,我还是新手,但我看不出有什么问题
这是密码Javascript 当我对此进行更改时,我的discord.js bot没有响应,我还是新手,但我看不出有什么问题,javascript,bots,discord,Javascript,Bots,Discord,这是密码 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 ${
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
的变量,然后检查其值是否为false。由于前缀
的值未定义,因此该值将始终计算为true
同样重要的是要指出,let前缀代码>正在用相同的名称隐藏全局常量