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

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

问题描述

我试图发出一个静音命令,我正在添加一个系统,您可以出于某种原因将它们静音.机器人会回复(用户的用户名)已静音.原因:(原因)》.对我来说 args[0] 只是提到您想静音的用户,但我不知道如何在 args[0] 之后获得所有内容.我试过做这样的事情 message.channel.send('I have muted' + (mutedUser) + 'Reason: ' + 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]?

推荐答案

argsslice() 的数组中取出要删除的参数个数,然后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天全站免登陆