此处是代码
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)
我已经测试了并且我的机器人已经在线了,我使用了更简单的代码,但是当我遇到这个问题时,它就不起作用了。我不明白为什么。香港专业教育学院做出了更改,也许我需要更多地了解“规则”或无法解决不一致的机器人代码的问题。
答案 0 :(得分:0)
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 prefix;
用相同的名称遮盖了全局const。