【问题标题】:Assigning a channel to a category in discord.js在 discord.js 中将频道分配给类别
【发布时间】:2020-03-05 14:57:03
【问题描述】:

我有一个在 Discord 服务器内创建频道的机器人。我在将频道分配给类别时遇到问题。

我的代码:

    if (!message.member.hasPermission("ADMINISTRATOR)")) return message.reply("nope");
if (command === "open") {
if (!args[0]) return message.channel.send('Proper usage: *open <name>');
let botmessage = args.join(" ");
message.guild.createChannel('????' + botmessage, { type: 'text' })
channel.setParent('[ID of Category here]')

机器人成功地创建了频道,但它没有分配到类别中。我得到的错误是:

“频道”未定义。

总的来说,我仍在学习 promise 和 discord.js。 如何让我的 Discord 机器人将创建的频道分配给指定的类别?

【问题讨论】:

    标签: node.js promise discord discord.js


    【解决方案1】:

    您需要使用.then() 来获取已解析的频道:

    message.guild.createChannel('?' + botmessage, { type: 'text' }).then((channel) => {
        channel.setParent('[ID of Category here]');
    });
    

    它会起作用的。 请注意,您也可以使用父选项创建频道:

    message.guild.createChannel('?' + botmessage, { type: 'text', parent: '[ID of Category here]' });
    

    通过这种方式,您无需使用 Promise,您将获得更好的性能。

    【讨论】:

    • 感谢您的回答,我得到了它的完美工作:)
    猜你喜欢
    • 1970-01-01
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 2015-06-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多