Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 为多台服务器的DiscordBot设置通道id_Javascript_Discord_Discord.js - Fatal编程技术网

Javascript 为多台服务器的DiscordBot设置通道id

Javascript 为多台服务器的DiscordBot设置通道id,javascript,discord,discord.js,Javascript,Discord,Discord.js,有人能帮我设置命令为特定服务器设置频道吗 这样它就不会相互干扰了?其实我有这个, var testChannel = bot.channels.find(channel => channel.id === "hereMyChannelID"); 我想设置所有者可以用来为其服务器设置频道id的命令。您可以通过创建一个JSON文件来保存每个公会的指定频道来完成此任务。然后,在命令中,只需在JSON中定义通道。之后,在代码中的任何其他地方,您都可以找到帮会所有者指定的频道并与之交互 请记住,数

有人能帮我设置命令为特定服务器设置频道吗 这样它就不会相互干扰了?其实我有这个,

var testChannel = bot.channels.find(channel => channel.id === "hereMyChannelID");

我想设置所有者可以用来为其服务器设置频道id的命令。

您可以通过创建一个JSON文件来保存每个公会的指定频道来完成此任务。然后,在命令中,只需在JSON中定义通道。之后,在代码中的任何其他地方,您都可以找到帮会所有者指定的频道并与之交互

请记住,数据库是一个更好的选择,因为它的速度比较快,而且腐败的风险要低得多。找到适合您和您的代码的JSON设置,并用数据库替换此JSON设置

guilds.json
设置:

{
  "guildID": {
    "channel": "channelID"
  }
}
命令代码:

{
  "guildID": {
    "channel": "channelID"
  }
}
/--在命令之外定义这些变量--
const-guilds=require('./guilds.json');
常数fs=要求('fs');
// ----------------------------------------------------
const args=message.content.trim().split(+/+/g);//可能已经宣布了。
试一试{
if(message.author.id!==message.guild.ownerID)返回wait message.channel.send('Access denied');
如果(!message.indications.channels.first())返回wait message.channel.send('Invalid channel');
公会[message.guild.id].channel=message.indications.channels.first().id;
fs.writeFileSync('./guilds.json',json.stringify(guilds));
等待message.channel.send('已成功更改频道');
}捕捉(错误){
控制台错误(err);
}
其他地方:

{
  "guildID": {
    "channel": "channelID"
  }
}
const-guilds=require('./guilds.json');
const channel=client.channels.get(公会[message.guild.id].channel);
中频(信道){
channel.send('找到正确的!')
.catch(控制台错误);
}else控制台。错误('无效或未定义的通道');