discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

[bug]: TypeError: newParent.permissionOverwrites.map is not a function #6030

Closed casperiv0 closed 3 years ago

casperiv0 commented 3 years ago

Please describe the problem you are having in as much detail as possible:

TypeError: newParent.permissionOverwrites.map is not a function error when calling the <Channel>.setParent function

Steps to reproduce

  1. Create a new channel
  2. Try updating the parent (\<Channel>.setParent())

Include a reproducible code sample here, if possible:

import { OverwriteResolvable, Permissions, Snowflake } from "discord.js";

const DEFAULT_PERMS: OverwriteResolvable[] = [
        {
          id: message.author.id,
          allow: [Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES],
        },
        {
          id: this.bot.user.id,
          allow: [Permissions.FLAGS.VIEW_CHANNEL, Permissions.FLAGS.SEND_MESSAGES],
        },
        {
          id: message.guild?.roles.everyone.id!,
          deny: [Permissions.FLAGS.VIEW_CHANNEL],
        },
];

const channel = await message.guild?.channels.create(
        "ticket",
        {
          type: "text",
          nsfw: false,
          permissionOverwrites: DEFAULT_PERMS,
        },
      );

    /**
    ERROR here: 

    TypeError: newParent.permissionOverwrites.map is not a function
    at TextChannel.edit (/home/casper/Projects/personal/ghostybot/node_modules/discord.js/src/structures/GuildChannel.js:313:66)
    at TextChannel.setParent (/home/casper/Projects/personal/ghostybot/node_modules/discord.js/src/structures/GuildChannel.js:375:17)
    */
      if (dbGuild.ticket_data.parent_id !== null) {
        channel.setParent(guild.ticket_data.parent_id as Snowflake);
      }

Further details:

Full error:

TypeError: newParent.permissionOverwrites.map is not a function
    at TextChannel.edit (/home/casper/Projects/personal/ghostybot/node_modules/discord.js/src/structures/GuildChannel.js:313:66)
    at TextChannel.setParent (/home/casper/Projects/personal/ghostybot/node_modules/discord.js/src/structures/GuildChannel.js:375:17)
    at CreateTicketCommand.execute (/home/casper/Projects/personal/ghostybot/src/commands/ticket/createticket.ts:83:18)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Full command here

Error stack leads to: https://github.com/discordjs/discord.js/blob/610b0b4dd6b6e66c05c22eb852d2a752b99d07ba/src/structures/GuildChannel.js#L313

Relevant client options:

SpaceEEC commented 3 years ago

This very valid bug report aside: GuildChannel#edit allows a parentID as part of the ChannelData, making the call to GuildChannel#setParent a superfluous API request.

casperiv0 commented 3 years ago

oh right. Thanks!