![](/img/trans.png)
[英]How can I make this slide code snippet loop infinetly ( my current code is not working and I don't know where I'm making mistakes)
[英]I'm making a rob command and I don't know how to make it activate the timeout when it fails or subtract the coins from the person
所以我正在研究我的不和谐机器人的经济部分,在发出抢劫命令时,它不会从被抢劫的人身上减去硬币,但它仍然会给我硬币。 我还希望它在您抢劫某人失败时激活超时,但它不会,所以有人可以帮忙吗?
我的抢命令代码:
const ms = require('parse-ms');
module.exports = {
name: "rob",
description: "Make an attempt to steal money from another user",
async run (client, message, args) {
let user = message.author;
let userMention = message.mentions.users.first()
let timeout = 7200000;
let author = await db.fetch(`worked_${message.guild.id}_${user.id}`);
let userBalance = await db.fetch(`money_${message.guild.id}_${getUserFromMention}`);
let amount = Math.floor(Math.random() * 80) + 1;
const robChance = Math.floor((Math.random() * 4) + 1);
if(userMention === undefined) return message.channel.send('Who do you want to rob?')
if(userMention === user) return message.channel.send('How stupid are you to rob yourself?')
if(userBalance > amount) return message.channel.send('They are to poor for you to rob.')
if(robChance === 0 ) return message.channel.send('The cops caught you and you couldn\'t get any money.')
if(author !== null && timeout - (Date.now() - author) > 0){
let time = ms(timeout - (Date.now() - author));
return message.channel.send(`The cops are looking for you. You shouldn't try and rob somebody else for another **${time.minutes}m** and **${time.seconds}s**.`)
} else {
db.add(`money_${message.guild.id}_${user.id}`, amount)
db.subtract(`money_${message.guild.id}_${getUserFromMention}`, amount)
db.set(`robbed_${message.guild.id}_${user.id}`, Date.now())
message.channel.send(`You robbed ${userMention} and got **${amount}** coins`)
}
}
}
function getUserFromMention(mention) {
if (!mention) return;
if (mention.startsWith('<@') && mention.endsWith('>')) {
mention = mention.slice(2, -1);
if (mention.startsWith('!')) {
mention = mention.slice(1);
}
return client.users.cache.get(mention);
}
}```
这是修复:
const ms = require('parse-ms');
module.exports = {
name: "rob",
description: "Make an attempt to steal money from another user",
async run (client, message, args) {
let user = message.author;
let userMention = message.mentions.users.first()
let timeout = 7200000;
let author = await db.fetch(`worked_${message.guild.id}_${user.id}`);
let userBalance = await db.fetch(`money_${message.guild.id}_${getUserFromMention}`);
let amount = Math.floor(Math.random() * 80) + 1;
const robChance = Math.floor((Math.random() * 4) + 1);
if(userMention === undefined) return message.channel.send('Who do you want to rob?')
if(userMention === user) return message.channel.send('How stupid are you to rob yourself?')
if(userBalance > amount) return message.channel.send('They are to poor for you to rob.')
if(robChance === 0 ) return message.channel.send('The cops caught you and you couldn\'t get any money.')
if(author !== null && timeout - (Date.now() - author) > 0){
let time = ms(timeout - (Date.now() - author));
return message.channel.send(`The cops are looking for you. You shouldn't try and rob somebody else for another **${time.minutes}m** and **${time.seconds}s**.`)
} else {
db.add(`money_${message.guild.id}_${user.id}`, amount)
db.subtract(`money_${message.guild.id}_${getUserFromMention}`, amount)
db.set(`robbed_${message.guild.id}_${user.id}`, Date.now())
message.channel.send(`You robbed ${userMention} and got **${amount}** coins`)
}
}
}
function getUserFromMention(mention) {
if (!mention) return;
if (mention.startsWith('<@') && mention.endsWith('>')) {
mention = mention.slice(2, -1);
if (mention.startsWith('!')) {
mention = mention.slice(1);
}
return client.users.cache.get(mention);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.