Javascript Condition: Cancel Command If Create Count Exceeds 1 Million
Apakah Anda ingin membuat kondisi if untuk membatalkan perintah jika user membuka create lebih dari 1000000?
import fetch from 'node-fetch'
const tfinventory = {
others: {
money: true,
},
tfitems: {
potion: true,
trash: true,
wood: true,
rock: true,
string: true,
emerald: true,
diamond: true,
gold: true,
iron: true,
},
tfcrates: {
common: true,
uncommon: true,
mythic: true,
legendary: true
},
tfpets: {
horse: 10,
cat: 10,
fox: 10,
dog: 10,
}
}
const rewards = {
common: {
money: 101,
trash: 11,
potion: [0, 1, 0, 1, 0, 0, 0, 0, 0],
common: [0, 1, 0, 1, 0, 0, 0, 0, 0, 0],
uncommon: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
},
uncommon: {
money: 201,
trash: 31,
potion: [0, 1, 0, 0, 0, 0, 0, 0],
diamond: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
common: [0, 1, 0, 0, 0, 0, 0, 0, 0],
uncommon: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
mythic: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
wood: [0, 1, 0, 0, 0, 0],
rock: [0, 1, 0, 0, 0, 0],
string: [0, 1, 0, 0, 0, 0]
},
mythic: {
money: 301,
exp: 50,
trash: 61,
potion: [0, 1, 0, 0, 0, 0],
emerald: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
diamond: [0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
gold: [0, 1, 0, 0, 0, 0, 1, 0, 0],
iron: [0, 1, 0, 0, 0, 0, 0, 0],
common: [0, 1, 0, 0, 0, 0],
uncommon: [0, 1, 0, 0, 0, 0, 0, 0],
mythic: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
legendary: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
pet: [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0],
wood: [0, 1, 0, 0, 0],
rock: [0, 1, 0, 0, 0],
string: [0, 1, 0, 0, 0]
},
legendary: {
money: 401,
exp: 50,
trash: 101,
potion: [0, 1, 0, 0, 0],
emerald: [0, 0, 0, 0, 0, 0 ,0, 0, 1, 0],
diamond: [0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
gold: [0, 1, 0, 0, 0, 0, 0, 0],
iron: [0, 1, 0, 0, 0, 0, 0],
common: [0, 1, 0, 0],
uncommon: [0, 1, 0, 0, 0, 0],
mythic: [0, 1, 0, 0, 0, 0, 1, 0, 0],
legendary: [0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
pet: [0, 1, 0, 0, 0, 0, 1, 0, 0, 0],
wood: [0, 1, 0, 0],
rock: [0, 1, 0, 0],
string: [0, 1, 0, 0]
},
}
let handler = async (m, { command, args, usedPrefix }) => {
let user = global.db.data.users[m.sender]
const tfcrates = Object.keys(tfinventory.tfcrates).map(v => user[v]
You can implement a simple if condition to check the user's 'create' count. Here's how:
if (user.create > 1000000) {
// If create count exceeds 1,000,000, send a message to the user.
m.reply('You have reached the maximum create limit! Please try again later.');
return;
}
Explanation:
user.create > 1000000: This condition checks if the user'screatecount is greater than 1,000,000.m.reply('You have reached the maximum create limit! Please try again later.');: This line sends a message to the user indicating that they've reached the limit.return;: This statement stops the execution of the command, preventing any further actions.
By incorporating this if condition, you can control the execution of the command based on the user's 'create' count, effectively preventing the command from being executed if the limit is exceeded.
Note: Ensure that user.create is a variable that accurately stores the user's 'create' count in your application's data structure.
原文地址: https://www.cveoy.top/t/topic/cZzM 著作权归作者所有。请勿转载和采集!