更改刚创建的频道的权限 [英] Change Permissions Of A Channel Just Created

查看:80
本文介绍了更改刚创建的频道的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,该代码旨在创建一个具有名称的新频道。这很好。然后,它需要设置频道的权限,以使所有用户的频道VIEW_CHANNEL为false。然后,它需要覆盖消息作者的权限,才能授予他们VIEW_CHANNEL。我陷入了如何使权限应用于刚刚创建的频道的麻烦。

I have the below code which is intended to create a new channel with a name. This works fine. It then needs to set the permissions of the channel to making it VIEW_CHANNEL false for all users. It then needs to overwrite permissions for the message author to grant them VIEW_CHANNEL. Im getting stuck on how to make the permissions apply on the channel just created.

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"
}


推荐答案

下面的代码有效:)

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"
}

这篇关于更改刚创建的频道的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆