我正在使用 message.guild.channels.create
创建一个频道。然后如何找到该频道的消息 ID 并在新创建的频道中发送消息?
message.guild.channels.create(`bug-priority${reportPriority}-${reportStart}`, {
type: 'text',
permissionOverwrites: [{
id: message.author.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
},
{
id: memberRole.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
}]
})
答案 0 :(得分:3)
guild.channels.create
返回一个解析为 GuildChannel 的承诺。这意味着您可以等待结果,那就是新创建的频道:
const channel = await message.guild.channels.create(`bug-priority${reportPriority}-${reportStart}`, {
type: 'text',
permissionOverwrites: [
{
id: message.author.id,
allow: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
},
{
id: memberRole.id,
deny: ['VIEW_CHANNEL', 'SEND_MESSAGES'],
},
],
});
const { id } = channel;
确保父函数是 async
函数。
答案 1 :(得分:1)
您可以在创建频道后使用 bot.channels.cache.find()
获取 id,如下所示:
let channel = bot.channels.cache.find(channel => channel.name === "name here");
let channelid = channel.id;
希望这有帮助!