【问题标题】:Get channel ID of newly created channel - Discord.js获取新创建频道的频道 ID - Discord.js
【发布时间】:2021-05-04 02:17:45
【问题描述】:

我正在尝试获取当用户对带有特定表情符号的消息做出反应时创建的频道的频道 ID。频道的创建完美无缺,唯一的问题是我无法获取创建的频道的 ID。

我使用以下代码来创建频道:

await message.guild.channels.create(`????│${name}`, {
    type: 'text',
    parent: 'CATEGORY_ID',
     permissionOverwrites: [{
         id: reactor,
         allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
     }]
});

现在我想获取该频道 ID,以便在创建后在其中发送消息。我一直在寻找答案,但还没有找到真正有效的答案。

【问题讨论】:

    标签: javascript node.js discord discord.js bots


    【解决方案1】:

    channels.create 返回一个带有 GuildChannel 的承诺,该承诺具有 id 属性。但是你甚至不需要那个ID,你可以在新创建的频道上使用.send方法:

    const createdChannel = await message.guild.channels.create(`?│${name}`, {
        type: 'text',
        parent: 'CATEGORY_ID',
         permissionOverwrites: [{
             id: reactor,
             allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
         }],
    });
    
    // createdChannel.id is the new channel's id
    const { id } = createdChannel;
    
    // but you can simply send a message with .send()
    createdChannel.send('This is a message in the new channel');
    

    【讨论】:

      猜你喜欢
      • 2020-07-26
      • 2021-02-06
      • 2020-08-12
      • 1970-01-01
      • 1970-01-01
      • 2021-09-19
      • 2021-10-12
      • 2023-03-27
      • 2021-04-04
      相关资源
      最近更新 更多