最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

如何通过使用命令来更改discord.js中的文件?

IT培训 admin 12浏览 0评论

如何通过使用命令来更改discord.js中的文件?

我尝试了很多事情。但是我无法使用命令更改配置文件。我想在该配置中添加频道ID

const fs = require('fs');
const config = require('../config.json')
const Discord = require('discord.js');
const client = new Discord.Client();
module.exports.run = async (client, message, args) => {

let owner = process.env.OWNER.split(',')
if(!owner.includes(message.author.id)) {
  return message.reply("This command is not made for everyone")
}
   if (message.channel.type === "dm" || message.author.bot || message.author === client.user) return; // Checks if we're on DMs, or the Author is a Bot, or the Author is our Bot, stop.

 fs.writeFile('./config.json', args[0], (err) => {
         if (err) console.log(err)
    })
  message.channel.send("Done")
}

exports.help = {
  name: "wtp",
  category: "General",
  description: "Add this channel into WTP",
  usage: "wtp <channel_id>"
};```
回答如下:

也可以这样,添加/更改配置变量,然后保存。

const fs = require('fs');
const config = require('../config.json')
const Discord = require('discord.js');
const client = new Discord.Client();
module.exports.run = async (client, message, args) => {

    let owner = process.env.OWNER.split(',')
    if(!owner.includes(message.author.id)) return message.reply("This command is not made for everyone")


    if (message.channel.type === "dm" || message.author.bot || message.author === client.user) return;  // Checks if we're on DMs, or the Author is a Bot, or the Author is our Bot, stop.

    if (args.length === 0) return message.reply('Pls mention a channell')
    let targetChannel = message.mentions.channels.first() || message.guild.channels.get(args[0])
    if (!targetChannel) return message.reply('Cant fin`d channel')
    config.channed_id = targetChannel.id


 fs.writeFile('./config.json',JSON.stringify(config) , (err) => {
         if (err) console.log(err);
         message.channel.send("Done")
    })
}

exports.help = {
  name: "wtp",
  category: "General",
  description: "Add this channel into WTP",
  usage: "wtp <channel_id>"
};

如何通过使用命令来更改discord.js中的文件?

我尝试了很多事情。但是我无法使用命令更改配置文件。我想在该配置中添加频道ID

const fs = require('fs');
const config = require('../config.json')
const Discord = require('discord.js');
const client = new Discord.Client();
module.exports.run = async (client, message, args) => {

let owner = process.env.OWNER.split(',')
if(!owner.includes(message.author.id)) {
  return message.reply("This command is not made for everyone")
}
   if (message.channel.type === "dm" || message.author.bot || message.author === client.user) return; // Checks if we're on DMs, or the Author is a Bot, or the Author is our Bot, stop.

 fs.writeFile('./config.json', args[0], (err) => {
         if (err) console.log(err)
    })
  message.channel.send("Done")
}

exports.help = {
  name: "wtp",
  category: "General",
  description: "Add this channel into WTP",
  usage: "wtp <channel_id>"
};```
回答如下:

也可以这样,添加/更改配置变量,然后保存。

const fs = require('fs');
const config = require('../config.json')
const Discord = require('discord.js');
const client = new Discord.Client();
module.exports.run = async (client, message, args) => {

    let owner = process.env.OWNER.split(',')
    if(!owner.includes(message.author.id)) return message.reply("This command is not made for everyone")


    if (message.channel.type === "dm" || message.author.bot || message.author === client.user) return;  // Checks if we're on DMs, or the Author is a Bot, or the Author is our Bot, stop.

    if (args.length === 0) return message.reply('Pls mention a channell')
    let targetChannel = message.mentions.channels.first() || message.guild.channels.get(args[0])
    if (!targetChannel) return message.reply('Cant fin`d channel')
    config.channed_id = targetChannel.id


 fs.writeFile('./config.json',JSON.stringify(config) , (err) => {
         if (err) console.log(err);
         message.channel.send("Done")
    })
}

exports.help = {
  name: "wtp",
  category: "General",
  description: "Add this channel into WTP",
  usage: "wtp <channel_id>"
};
发布评论

评论列表 (0)

  1. 暂无评论