简体   繁体   English

如何为 discord.js 中的机器人所在的每个 discord 服务器制作不同的阵列?

[英]How do you make a different array for each discord server a bot is on in discord.js?

I had been making a bot in discord where you could add items to a list and everyone could see them.我一直在 discord 中制作一个机器人,您可以在其中将项目添加到列表中,每个人都可以看到它们。 It would going very smoothly, but I ran into a problem.它会非常顺利,但我遇到了一个问题。 When I tested to bot in multiple servers, the list stayed the same in each server, and I couldn't find out a way to fix it, I've tried looking up answers but the answers I found didn't have to do with my case.当我在多台服务器上测试机器人时,每台服务器的列表保持不变,我找不到修复它的方法,我尝试查找答案,但我找到的答案与我的情况。 so I'm asking here, So?所以我在这里问,所以? how am I able to create an array automatically for each server a discord bot is in. This could help others using arrays in their discord bot.我如何能够为 discord 机器人所在的每个服务器自动创建一个阵列。这可以帮助其他在 discord 机器人中使用 arrays 的人。

As a first approach, you can use the HashMap npm package.作为第一种方法,您可以使用HashMap npm package。 HashMap permits to associate a key and a value. HashMap 允许关联键和值。 So you are going to store for each server a list.因此,您将为每个服务器存储一个列表。 And for the key, you are going to take the server ID.对于密钥,您将获取服务器 ID。

Check the documentation for a list of all possibilities.检查文档以获取所有可能性的列表。

An example can be:一个例子可以是:

var HashMap = require('hashmap');

var map = new HashMap();

//Store the item's list.
map.set("Your guild ID / message.guild.id", "Your item list");

//Then, in order to get it, just do.
map.get("Your guild ID / message.guild.id");

If you want more possibilities, you can always have a look at SQL/SQLite.如果您想要更多的可能性,您可以随时查看 SQL/SQLite。 For example, using Enmap .例如,使用Enmap

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

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