为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

牛魔王的故事 2023-04-14 15:33:20
当我去第一台服务器时,我使用命令保存数组 第二台服务器使用命令保存数组,但保存相同我想要它使用另一个新阵列,我该怎么做?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);                })            }    }顺便说一下,我的数组命令没有完成!
查看完整描述

1 回答

?
一只斗牛犬

TA贡献1784条经验 获得超2个赞

您不能使用相同的客户端和相同的变量来存储所有不同服务器的 Music 数组。一种方法是为每台服务器设置不同的变量,如果您事先知道您的机器人将使用多少台服务器,


const musicQ1 = new Array(); // for server 1

const 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();

}

另一种选择是使用数据库为不同服务器的队列存储具有不同位置的队列数据。最终由您决定如何通过服务器分离和访问队列数据。


查看完整回答
反对 回复 2023-04-14
  • 1 回答
  • 0 关注
  • 86 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信