简体   繁体   English

discord.js 将参数与命令合并的方法?

[英]discord.js way to merge args with command?

I was wondering if(for a discord.js bot) you could have a command be a letter, but also have a word also right next to the command, so....我想知道(对于 discord.js 机器人)您是否可以让一个命令是一个字母,但也可以在命令旁边有一个单词,所以......

#i Dog #我是狗

would be将会

#iDog #爱狗

where 'i' would be the command and 'Dog' would be the 0 args, but would become part of the command because I want to eventually do species of dog and I think it would look silly if I did #i Dog NAME_OF_DOG plus I have a command handler, so I would have to do其中“i”将是命令,“Dog”将是 0 args,但会成为命令的一部分,因为我最终想做 species of dog 我认为如果我做#i Dog NAME_OF_DOG plus I 会看起来很傻有一个命令处理程序,所以我必须这样做

 else if(command === 'i') { client.command.get('images').execute(); }

everytime I wanted to do Multiple animals with spieces, and I do plan to add not only multiple animals, but all sorts of images,每次我想用 spieces 做 Multiple animals 时,我确实计划不仅要添加多个动物,还要添加各种图像,

You can always use message.content and trim the first letter out and treat it as arguments and to check for a command, use message.content.startsWith() :您始终可以使用 message.content 并修剪第一个字母并将其视为 arguments 并检查命令,使用message.content.startsWith()

let str = "idog"; // Message content 
let args = str.slice(1); 
console.log(args)

The above code results args as dog.上面的代码结果args为狗。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM