简体   繁体   English

如何在不和谐的消息中找到一个数字?

[英]How to find a number in a message on discord?

I'm making a bot on discord and I want the bot to detect how much the person says in his message and who he mentioned, ex.我正在制作一个不和谐的机器人,我希望机器人检测这个人在他的信息中说了多少以及他提到的是谁,例如。 >command @user 7853. I know that >command @user 7853。我知道

message.mentions.users.first().id

finds the first-mentioned user but I don't know how to find the number that they said.找到第一个提到的用户,但我不知道如何找到他们说的号码。 Can someone tell me the correct script for that?有人可以告诉我正确的脚本吗?

message.content is the content of the message so you only need to parse that like: message.contentmessage.content的内容,所以你只需要像这样解析:

const args = message.content.slice(prefix.length).trim().split(/ +/);
const command = args.shift();

This will convert the message into an array like ['@user', '7853'] .这会将消息转换为类似['@user', '7853']的数组。 Now you can just do args[1] and you will get the number.现在您只需执行args[1]获得数字。

If you are interested and want to learn more you can do here: https://discordjs.guide/ , this is the guide made by the community of discord.js and includes a section about setting up commands you need.如果您有兴趣并想了解更多信息,可以在此处进行: https://discordjs.guide/ : https://discordjs.guide/ ,这是由discord.js社区制作的指南,其中包含有关设置所需命令的部分。

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

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