The parameter provided is neither a User nor a Role, resulting in a TypeError of INVALID_TYPE in Discord.js

After initially coding these functions, I encountered an unexpected behavior with .overwritePermissions() erasing set permissions. Upon revisiting my code to address this issue, I aimed to modify joinPrivateChannel() to utilize .updateOverwrite() in order to avoid wiping out the channel permissions for the user creating the channel.

The function createPrivateChannel() consistently operates without any issues, whereas the second function triggers the error

TypeError [INVALID_TYPE]: Supplied parameter is not a User nor a Role.
. Despite attempting various approaches like hardcoding a user ID, member variable, role ID, and role variable, no solution seemed to resolve the problem. If any further details are needed, please feel free to ask. Thank you for your assistance.

async function createPrivateChannel(serverId, channelName, message) {
  const guild = await client.guilds.fetch(serverId);
  const everyoneRole = guild.roles.everyone;
  const staffRole = guild.roles.Owner;
  const channel = await guild.channels.create(channelName, 'lobby')
  await channel.setParent(lobby_category);
  await channel.overwritePermissions([
    {type: 'member', id: message.author.id, allow: [Permissions.FLAGS.VIEW_CHANNEL]},
    {type: 'role', id: everyoneRole.id, deny: [Permissions.FLAGS.VIEW_CHANNEL]},
  ]);
  channel.send('+start');
  return;
}

async function joinPrivateChannel(serverId, channel, message){
    const guild = await client.guilds.fetch(serverId);
    await channel.updateOverwrite([
        {type: 'member', id: message.author.id, allow: [Permissions.FLAGS.VIEW_CHANNEL]},
    ]);
};

Answer №1

According to the djs documentation, it seems that the updateOverwrite method does not support arrays in its syntax. It's possible that there was a misunderstanding regarding the parameters used.

The updateOverwrite method accepts the following parameters: (userOrRole, options, reason).

In your specific scenario

await channel.updateOverwrite(message.author.id,
        {VIEW_CHANNEL: true},
    );

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Discover the Names of Elements associated with the identical Input File tag

Having a bit of trouble with my jQuery code here. I've got two HTML input file elements with different names. How can I retrieve the name of the second input file using jQuery? Below is my HTML markup: <input type="file" name="photo_a" /> &l ...

Differences in Function Scope: A Comparison of ECMAScript 6 and ECMAScript 5

What are the advantages of ES6 compared to ES5 when it comes to block scope functions? Although the blocks may look similar in both cases, what impact does it have performance-wise and which approach is more efficient? ES6 Block { function fo ...

Error: The object #<HTMLCollection> does not support the 'tags' method

While trying to troubleshoot this issue, it seems like I haven't been able to pinpoint the simple solution. This particular javascript menu works perfectly in IE, however in Chrome, there is an error when trying to open the menu with a first-level cli ...

incapable of modifying the JSON file on the client end

In my JavaScript code, I am attempting to edit a JSON file named "client.json" located on the local system. The file is only modified locally. A form is used to collect new client details, and I aim to append these details as an object to the JSON file. ...

In need of assistance with posting data on a Captive Portal using Ruckus AccessPoint Javascript

We are currently working on implementing a captive portal using Ruckus AP for our guests. Our setup includes a form where users can input their username and password. Upon clicking "Login", we aim to post this data to the Ruckus AP's user_login_auth. ...

Using MeanJS to assign a Mongoose object reference to an array in Angular

Having an issue with MeanJS and using the $update function of the $resource service in Angular provided by MeanJS. Here is a basic outline of my problem: Mongoose schema: var mongoose = require('mongoose'), Schema = mongoose.Schema; var Lotion ...

Discovering the equivalent of the onchange event through javascript dom and jquery

I am working with HTML code that involves triggering a function in the onChange event of a select box. <select id="locationLevelId" onChange="abc();"> Currently, I am looking to achieve the same effect using JavaScript DOM and jQuery, specifically ...

What should be transmitted to the front-end following the successful validation of a token on the server?

My process starts with a login page and then moves to the profile page. When it comes to handling the token on the backend, I use the following code: app.use(verifyToken); function verifyToken(req, res, next) { if (req.path === '/auth/google&ap ...

Dynamic counter with Javascript or Ajax functionality

Is there a way to create a counter using JavaScript or Ajax that preserves its count even when the page is refreshed? <script type="text/javascript"> var totalCount = parseInt(localStorage.getItem('counter')) || 0; document.getElementById ...

Troubleshooting Vue.js: Why is .bind(this) not behaving as anticipated?

Demo: https://codesandbox.io/s/23959y5wnp I have a function being passed down and I'm trying to rebind the this by using .bind(this) on the function. However, the data that is returned still refers to the original component. What could I be missing h ...

Tips for utilizing promises to create automated waiting for a function's completion in node.js/javascript

When I instantiate a module, it triggers numerous asynchronous functions. var freader = new filesreader(); // <-- this triggers multiple async functions var IMG_ARRAY = freader.get_IMG_ARRAY(); // <-- i retrieve the array where content is store ...

ways to animate the closing of a dropdown menu

I'm currently working on a navbar dropdown animation code that works on hover. However, I've encountered an issue when trying to use it on a phone - I can open the dropdown, but I can't seem to close it. Does anyone have suggestions on how ...

Changing synchronous functions to asynchronous

Attempting to transform synchronous calls into asynchronous ones using when...done. Despite being new at this, after extensive reading on the topic for the past two days, my code should work as intended. However, while it does function, it doesn't exe ...

When a Vue.js Directive is inserted or bound, it actually takes precedence over the click event

Imagine having multiple dropdowns or elements on the page that all utilize a directive called "closable". This directive triggers an expression if the element clicked is outside of the element using the directive. The intended behavior is that when clicki ...

A guide to displaying API response data in a React JS application

As a beginner in react JS, I've encountered a persistent issue. Here is the code: import React from 'react'; class SearchForm extends React.Component { async handleSubmit(event){ event.preventDefault(); try{ const url ='/jobs/ ...

The button in discord.js is unresponsive and does not seem to be

Hey there! I've written some code for a specific function. However, when I run the command, only the text is displayed in my channel and not the buttons. I'm puzzled as to why this is happening because I don't see any errors. Can anyone help ...

Establishing data information on dynamically generated HTML

When I receive a JSON response from the server, it contains an array with 32 objects. Here's an example: [{object1}, { object2}, { object3}, etc]. To populate an HTML template with information from each object, I use a simple loop like this: for (v ...

Dealing with Asynchronous JavaScript code in a while loop: Tips and techniques

While attempting to retrieve information from an API using $.getJSON(), I encountered a challenge. The maximum number of results per call is limited to 50, and the API provides a nextPageToken for accessing additional pages. In the code snippet below, my i ...

Error: npm encountered a socket timeout issue

Setting up a fresh React application in /home/abhijith/Desktop/React/firstReact/myapp. Installing necessary packages. This process may require a few minutes. Installing react, react-dom, and react-scripts along with cra-template... npm ERR! code ERR_SOCK ...

Using jQuery's .load() method to load a PHP file can result in an exponential increase in XHR finished loading time with each subsequent load

There seems to be an issue with my code using .load() to load a PHP page into a div whenever the navbar or link is clicked. After multiple clicks, I noticed that the "XHR finished loading" increases exponentially and it appears that the same PHP file is be ...