在args [0] discord.js之后获取所有参数 [英] Get all arguments after args[0] discord.js

查看:43
本文介绍了在args [0] discord.js之后获取所有参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发出一个静音命令,并且我添加了一个可以使它们静音的系统.机器人将回复(用户的用户名)已被静音.原因:(原因)".对我来说,args [0]只是提到您要静音的用户,但是我不知道如何在args [0]之后获得全部.我试图做这样的事情 message.channel.send('我已经静音'+(mutedUser)+'原因:'+ args [1 ++] .但这显然没有用-我有点猜测-我转向列出这样的4个参数.

I was trying to make a mute command, and I was adding a system where you can mute them for a reason. The bot would reply "(Username of user) was muted. Reason: (The reason)". For me args[0] is just mentioning the user that you want to mute, but I can't figure out how to get all after args[0]. I've tried doing something like this message.channel.send('I have muted' + (mutedUser) + 'Reason: ' + args[1++]. But that obviously didn't work - I was kind of guessing - I turned to listing 4 arguments like this.

message.channel.send('I have muted ' + taggedUser.user.username + ' Reason: ' + args[1] + ' ' + args[2] + ' ' + args[3] + ' ' + args[4])

但是显然,这不是很有效-有人知道如何在args [0]之后获取所有参数吗?

But obviously, that's not very efficient - Does anyone know how to get all arguments after args[0]?

推荐答案

获取要删除的参数数量的 args slice()数组,然后 join()将其余的数组元素合并为一个字符串

Take the array of args and slice() the number of arguments you want to delete, then join() the remaining array elements into a single string

快速提示使用模板文字可以更轻松地使用字符串和变量进行格式化

Quick Tip Use Template literals for easier formatting with strings and variables

const reason = args.slice(1).join(' ');

message.channel.send(`I have muted ${mutedUser}, Reason: ${reason}`);

这篇关于在args [0] discord.js之后获取所有参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆