私はDiscord、js-commandoライブラリで簡単なDiscordボットをコーディングしようとしています。これまでのところほとんどの作業を行っていましたが、問題が残っています。あなたは!ロールを行うことができますし、それは1から6までの数をランダムに選択しますが、私はカスタムので、ここでそれはもう少し作りたかったところ、それはdiscord botカスタムコマンドJS
次のようになります!ロール(1から6までロールス)
!ロール25(1から25までロールス)
が!100 200(100から200までロール)ロール
問題は私がしようとするときです!ロール25私の検証は有効な数字ではないと言っていますが、他のすべてのコマンドはうまくいきます。それはおそらく、事前
const commando = require('discord.js-commando')
const _ = require('lodash')
class DiceRollCommand extends commando.Command {
constructor(bot) {
super(bot, {
name: 'roll',
group: 'random',
memberName: 'roll',
description: 'Rolls a dice.'
})
}
async run(message, args) {
let roll = args.split(' ')
let hasNumber = /^[0-9]$/
if (roll[0] || roll[1]) {
if (!hasNumber.test(roll[0]) || !hasNumber.test(roll[1])) {
console.log('roll[1] -> '+ !hasNumber.test(roll[0])) // returns true
console.log('roll[2] -> '+ !hasNumber.test(roll[1])) // returns true
message.reply('[DEBUG] Syntax Error input must be a number')
return
}
}
if (roll.length >= 3) {
message.reply('[DEBUG] Syntax Error cannot use more than 2 parameters')
return
}
if (roll[0] > 1000000 || roll[1] > 1000000) {
message.reply('Unfortunately for you, computers have a limited amount of memory, so unless you want me to run out, stop sending ludicrous numbers. Thanks.')
return
}
if (message.content.match(/^!roll$/)) {
message.reply('rolled ' + _.random(1, 6))
}
if (message.content.match(/^!roll [0-9]+\b/)) {
message.reply('rolled ' + _.random(1, roll[0]))
}
if (message.content.match(/^!roll ([0-9]*) ([0-9]*)+\b/)) {
message.reply('rolled ' + _.random(roll[0], roll[1]))
}
}
}
module.exports = DiceRollCommand
ありがとうございました;) – John
["b"、 "3"]が数値の検証に合格するため、これは間違っています – xDreamCoding
["b"、 "3"]とはどういう意味ですか?私はそれが今すべての作品を参照してください – John