代码之家  ›  专栏  ›  技术社区  ›  Daniel Vickers

更改刚创建的频道的权限

  •  0
  • Daniel Vickers  · 技术社区  · 8 年前

    我有下面的代码,打算创建一个新的频道名称。这很管用。然后,它需要设置频道的权限,使其对所有用户的查看频道为false。然后,它需要覆盖消息作者的权限,以授予他们查看频道的权限。我被困在如何使权限应用于刚刚创建的频道。

    const Discord = require("discord.js");
    
    module.exports.run = async (bot, message, args) => {
    
    let botIcon = bot.user.displayAvatarURL;
    let ticketEmbed = new Discord.RichEmbed()
    .setDescription("TicketBot")
    .setColor("#bc0000")
    .setThumbnail(botIcon)
    .addField("New Ticket", `${message.author} your ticket has been created.`);
    
    let ticketchannel = message.guild.channels.find(`name`, "bot-testing");
    if(!ticketchannel) return message.channel.send("Couldn't find bot testing channel.");
    
    ticketchannel.send(ticketEmbed);
    
    function getRandomInt(max) {
      return Math.floor(Math.random() * Math.floor(max));
    }
    let ticketid = getRandomInt(10000);
    let name = `ticket-${message.author.username}-${ticketid}`;
    
    message.guild.createChannel(name, "text")
    .then(
    
        message.channel.overwritePermissions(message.author, {
            VIEW_CHANNEL: true
        })
    );    
    }
    
    module.exports.help = {
        name: "new"
    }
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Daniel Vickers    8 年前

    以下代码起作用:)

    const Discord = require("discord.js");
    
    module.exports.run = async (bot, message, args) => {
    
    let botIcon = bot.user.displayAvatarURL;
    let ticketEmbed = new Discord.RichEmbed()
    .setDescription("TicketBot")
    .setColor("#bc0000")
    .setThumbnail(botIcon)
    .addField("New Ticket", `${message.author} your ticket has been created.`);
    
    let ticketchannel = message.guild.channels.find(`name`, "bot-testing");
    if(!ticketchannel) return message.channel.send("Couldn't find bot testing channel.");
    
    ticketchannel.send(ticketEmbed);
    
    function getRandomInt(max) {
      return Math.floor(Math.random() * Math.floor(max));
    }
    let ticketid = getRandomInt(10000);
    let name = `ticket-${message.author.username}-${ticketid}`;
    
    message.guild.createChannel(name, "text")
    .then(m => {
        m.overwritePermissions(message.guild.id, {
            VIEW_CHANNEL: false
        })
    
        m.overwritePermissions(message.author.id, {
            VIEW_CHANNEL: true
        })
    })
    //channel.delete()
    }
    
    module.exports.help = {
        name: "new"
    }