如何在确认消息中间隔显示禁令的原因



因此,每当用户被我的Discord.js机器人的ban命令禁止时,在用户提及后面指定的原因不会在确认消息中被隔开。我已经将禁止原因存储在以下代码中:const banReason = args.slice(1).join('');,并在消息中使用它作为.addFields({ name: 'Reason', value: ``${banReason}`` })。但每当机器人返回消息时,所有作为禁令原因的文本都不会被隔开。例如,如果我要输入-ban @User No spacing,它将在确认消息中显示原因为Nospacing。所以问题是,你如何解释禁令的原因?

在我给你答案之前,我想给你上一堂关于.join()的"课">

.join()方法用于将数组的元素连接在一起。

// For example, if we take the following array and use the join method on it, we'll get:
const fruits = ['apple', 'orange', 'watermelon'];
fruits.join();
// Expected Output: 'apple,orange,watermelon'
// .join() automatically defaults the joining to have ',' between the elements if no argument was provided.

尽管在某些情况下,我们显然希望以不同的方式分离元素,但这看起来会更干净一些。在这里,我们可以传递一个特定的论点,将元素彼此分离。

// For example:
fruits.join('');
// Expected Output: 'appleorangewatermelon'

从这里开始,由于您的参数基本上是用户给定的元素数组,我们可以简单地使用将它们与一个空格连接起来

fruits.join(' ');
// Expected Output: 'apple orange watermelon'
// from this, we learn that the answer to your problem is: args.slice(1).join(' ');

祝你好运!

您必须制作

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

因为你希望单词之间有空格。你的错误只是什么都没加入。

最新更新