3 回答

TA貢獻1828條經(jīng)驗 獲得超4個贊
您的字符串連接錯誤。target.id 之后的字符串前不應(yīng)有感嘆號。
如果這樣做,它將連接真值,轉(zhuǎn)換為字符串,因此在本例中為“false”。
你現(xiàn)在擁有的(壞的)
'test' + !'string' // >> 'testfalse'
你需要什么(好)
'test' + 'string' // >> 'teststring'
如果你只是刪除它應(yīng)該工作!來自 db.has

TA貢獻1871條經(jīng)驗 獲得超8個贊
試試這個結(jié)構(gòu)
async run(client, message, args) {
...
const match = {
userPet : "",
targetPet : ""
}
["hamster","dog","cat"].forEach(pet => {
if (db.has(user.id.items[pet])) match.userPet = pet
if (db.has(target.id.items[pet])) match.targetPet = pet
});
if (!match.userPet) { message.channel.send('You need a pet to fight'); return }
if (!match.targetPet) {message.channel.send('Your opponent needs a pet to fight'); return; }
message.channel.send('your all good!')
}

TA貢獻1793條經(jīng)驗 獲得超6個贊
我用這段代碼修復(fù)了它:
const Discord = require('discord.js');
module.exports = {
name:"fight",
description:"fight someone",
async run (client, message, args){
let target = message.mentions.users.first();
if(!target)return message.channel.send('please provide a person to fight');
let user = message.author;
let theitemsofuser = await db.fetch(message.author.id, { items: []});
if(target === user) return message.channel.send('You can\'t fight yourself!')
if(!db.has(user.id + '.items', 'hamster'))return message.channel.send('you need a pet to fight');
if(!db.has(user.id + '.items', 'dog'))return message.channel.send('you need a pet to fight');
if(!db.has(user.id + '.items', 'cat'))return message.channel.send('you need a pet to fight');
if(!db.has(target.id + '.items', 'hamster'))return message.channel.send('your opponent needs a pet to fight');
if(!db.has(target.id + '.items', 'dog'))return message.channel.send('your opponent needs a pet to fight');
if(!db.has(target.id + '.items', 'cat'))return message.channel.send('your opponent needs a pet to fight');
message.channel.send('your all good!')
}}```
Fixes: I used !db.has(user.id + '.items', 'dog') return message.channel.send('you dont have a dog at the moment') Instead of db.has(user.id + '.items', 'dog') return message.channel.send('you dont have a dog at the moment')
添加回答
舉報