Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/444.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 我可以设置字符串以在保存时自动更新富嵌入吗?Discord.js_Javascript_Node.js_Json_Discord_Discord.js - Fatal编程技术网

Javascript 我可以设置字符串以在保存时自动更新富嵌入吗?Discord.js

Javascript 我可以设置字符串以在保存时自动更新富嵌入吗?Discord.js,javascript,node.js,json,discord,discord.js,Javascript,Node.js,Json,Discord,Discord.js,所以我想知道我是否可以这样做,如果我在config.json文件中更改并保存一个字符串,它会自动更新一个丰富的嵌入。我这样做是为了我的服务器的队列系统 我已经在discord.js服务器上试过了,他们说可以,但没有给我进一步的帮助 config.json文件: { "prefix": "dsc", "token": "im not showing you", "server"

所以我想知道我是否可以这样做,如果我在config.json文件中更改并保存一个字符串,它会自动更新一个丰富的嵌入。我这样做是为了我的服务器的队列系统

我已经在
discord.js
服务器上试过了,他们说可以,但没有给我进一步的帮助

config.json
文件:

{
    "prefix": "dsc",
    "token": "im not showing you",
    "server": "1 Day",
    "bot": "",
    "icon": ""
}
const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
const { Client, MessageEmbed } = require("discord.js");
const prefix = "config.prefix";
const fs = require("fs");

client.commands = new Discord.Collection();

client.once("ready", () => {
  console.log("DSC BOT is now online!");
});

client.on("message", (message) => {
  if (!message.content.startsWith(prefix) || message.author.bot) return;

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

  //command code

  if (command === "ping") {
    message.channel.send("Pong!");
  } else if (command === "test") {
    message.channel.send(config.server);
  }
});

client.on("message", (message) => {
  if (message.content === "dsc test") {
    message.channel.send(
      "Hello There, this is a test!",
      config.server,
      "It should say yolo <<"
    );
  }
});

client.on("message", (message) => {
  if (message.content === "dsc updates") {
    const updates = new MessageEmbed()
      .setTitle("DSC Updates")
      .setColor("#0099ff")
      .addFields(
        { name: "Server:", value: config.server },
        { name: "Regular field title", value: "Some value here" }
      )
      .setFooter("DSC");
    message.channel.send(updates);
  }
});

client.login(config.token);
main.js
文件:

{
    "prefix": "dsc",
    "token": "im not showing you",
    "server": "1 Day",
    "bot": "",
    "icon": ""
}
const Discord = require("discord.js");
const client = new Discord.Client();
const config = require("./config.json");
const { Client, MessageEmbed } = require("discord.js");
const prefix = "config.prefix";
const fs = require("fs");

client.commands = new Discord.Collection();

client.once("ready", () => {
  console.log("DSC BOT is now online!");
});

client.on("message", (message) => {
  if (!message.content.startsWith(prefix) || message.author.bot) return;

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

  //command code

  if (command === "ping") {
    message.channel.send("Pong!");
  } else if (command === "test") {
    message.channel.send(config.server);
  }
});

client.on("message", (message) => {
  if (message.content === "dsc test") {
    message.channel.send(
      "Hello There, this is a test!",
      config.server,
      "It should say yolo <<"
    );
  }
});

client.on("message", (message) => {
  if (message.content === "dsc updates") {
    const updates = new MessageEmbed()
      .setTitle("DSC Updates")
      .setColor("#0099ff")
      .addFields(
        { name: "Server:", value: config.server },
        { name: "Regular field title", value: "Some value here" }
      )
      .setFooter("DSC");
    message.channel.send(updates);
  }
});

client.login(config.token);
const Discord=require(“Discord.js”);
const client=new Discord.client();
const config=require(“./config.json”);
const{Client,MessageEmbed}=require(“discord.js”);
const prefix=“config.prefix”;
常数fs=要求(“fs”);
client.commands=new Discord.Collection();
client.once(“就绪”,()=>{
log(“DSC机器人现在在线!”);
});
client.on(“message”,(message)=>{
如果(!message.content.startsWith(prefix)| | message.author.bot)返回;
const args=message.content.slice(prefix.length.trim().split(“”);
const命令=args.shift().toLowerCase();
//命令代码
如果(命令==“ping”){
message.channel.send(“Pong!”);
}else if(命令==“测试”){
message.channel.send(config.server);
}
});
client.on(“message”,(message)=>{
如果(message.content==“dsc测试”){
message.channel.send(
“你好,这是一个测试!”,
config.server,

“它应该是yolo而不是使用常量字符串设置您的bot,通过要求您的
config.json
并将其添加到嵌入中来使用它。下面是这样一个示例:

const Discord=require('Discord.js');
const client=new Discord.client();
const config=require('./config.json');
const{Client,MessageEmbed}=require('discord.js');
const prefix=config.prefix;//不要添加“”,它会将其转换为常量字符串。
常数fs=要求('fs');
client.commands=new Discord.Collection();//正在学习命令处理程序?如果是这样,我将不再讨论这个问题。
client.on('ready',()=>{
//'client.one('',()=>{})`不起作用。
log('DSC BOT现在联机!');
});
client.on('消息',(消息)=>{
//只要定义一次,然后把所有的东西都放进去。
如果(!message.content.startsWith(prefix)| | message.author.bot)返回;
const args=message.content
.slice(前缀.length)
.trim()
.分割(“”);
const命令=args.shift().toLowerCase();
//命令代码//
如果(命令=='ping'){
message.channel.send('Pong!');
}else if(命令==='test'){
message.channel.send(config.server);
}
如果(message.content===“dsc测试”){
message.channel.send(
“你好,这是一个测试!”,
config.server,
“应该是约洛