[Discord.Js]如何在另一台服务器上获取新的保存

当我去第一台服务器时,我使用命令保存数组 第二台服务器使用命令保存数组,但保存相同


我想要它使用另一个新阵列,我该怎么做?


const Music_Queue = new Array();

class Music {

    

    constructor() {

        this.connection = {};

    }


    play(msg) {

        //if Bot Not Join The Server

        if (!this.connection[msg.guild.id]) 

        {

            music.join(msg);

        }


        //RePlace "!Play",Get Url

        const musicURL = msg.content.replace(`${prefix}play`, '');

        const voiceChannel = msg.member.voice.channel;

        if(Music_Queue.length == 0)

            {

                Music_Queue[0] = musicURL;

                music.playmusic(Music_Queue[0],voiceChannel,msg);

            }

        else

            {

                Music_Queue[Music_Queue.length + 1] = musicURL;

                getInfo(musicURL).then(info => {

                    const exampleEmbed = new Discord.MessageEmbed()

                    .setColor('#0FFFFF')

                    .addField(`Add Music!『 ${info.items[0].title} 』`)

                    .setTimestamp();

                    msg.channel.send(exampleEmbed);

                })

            }

    }

顺便说一下,我的数组命令没有完成!


牛魔王的故事
浏览 87回答 1
1回答

一只斗牛犬

您不能使用相同的客户端和相同的变量来存储所有不同服务器的 Music 数组。一种方法是为每台服务器设置不同的变量,如果您事先知道您的机器人将使用多少台服务器,const musicQ1 = new Array(); // for server 1const musicQ2 = new Array(); // for server 2或者您可以创建一个 JS 对象,其中服务器 ID 作为键,它们的唯一数组作为值,const queueObject = {"server_1_ID" : musicQ1 , "server_2_ID" : musicQ2};并检查以确保在某个函数的对象中为新服务器分配了空间,if (typeof queueObjects["server_new_ID"] === "undefined") {    queueObject["server_new_ID"] = new Array();}另一种选择是使用数据库为不同服务器的队列存储具有不同位置的队列数据。最终由您决定如何通过服务器分离和访问队列数据。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript