为了账号安全,请及时绑定邮箱和手机立即绑定

我如何确保此人从商店购买了某件商品?

我如何确保此人从商店购买了某件商品?

饮歌长啸 2023-05-18 11:11:40
我已经遇到这个问题好几个小时了,我无法确保人们在与宠物进行活动之前已经购买了宠物。它没有显示错误,但它不能正常工作,我不知道如何引用玩家库存中的某个项目,因为我正在尝试实现一个宠物功能,你可以在其中与其他人打宠物,也将能够喂养你的宠物,并且会有宠物比赛和统计等活动。const db = require('quick.db');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!')  }}
查看完整描述

3 回答

?
明月笑刀无情

TA贡献1828条经验 获得超4个赞

您的字符串连接错误。target.id 之后的字符串前不应有感叹号。

如果这样做,它将连接真值,转换为字符串,因此在本例中为“false”。

你现在拥有的(坏的)

'test' + !'string'
// >> 'testfalse'

你需要什么(好)

'test' + 'string'
// >> 'teststring'

如果你只是删除它应该工作!来自 db.has


查看完整回答
反对 回复 2023-05-18
?
ITMISS

TA贡献1871条经验 获得超8个赞

试试这个结构


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!')

}


查看完整回答
反对 回复 2023-05-18
?
摇曳的蔷薇

TA贡献1793条经验 获得超6个赞

我用这段代码修复了它:


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')



查看完整回答
反对 回复 2023-05-18
  • 3 回答
  • 0 关注
  • 107 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信