【问题标题】:Change Permissions Of A Channel Just Created更改刚刚创建的频道的权限
【发布时间】:2018-12-15 02:03:26
【问题描述】:

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

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

【问题讨论】:

  • 不要使用message.channel,而是尝试使用从createChannel返回的频道,例如message.guild.createChannel(name, "text").then(function(channel) { channel.overwritePermissions(message.author, { VIEW_CHANNEL: true }); });
  • 另外,直接向用户发送他们的票而不是为其创建一个频道可能会更好?那么您就不必担心名称冲突或机器人没有创建频道的权限
  • 很遗憾,您建议的修改无效。并且必须是一个频道,因为工作人员将回复票证并协助解决问题。

标签: javascript discord discord.js


【解决方案1】:

下面的代码有效:)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-06-30
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 2021-02-01
    • 1970-01-01
    • 2019-05-07
    • 2016-12-09
    相关资源
    最近更新 更多