Error pops up on startup: 'Incorrect login details were provided' - discord.js

I'm following the guide. I've run node index.js into Windows PowerShell, but it's not giving intended output
It's copy and pasted from the discord.js guide. I've run it many times and every time it has the same exact error.
// require the discord.js module
const Discord = require('discord.js');
// create a new Discord client
const client = new Discord.Client();
// when the client is ready, run this code
// this event will only trigger one time after logging in
client.once('ready', () => {
console.log('Ready!');
});
// login to Discord with your app's token
client.login('your-token-goes-here');
expected: Ready!
actual:
(node:800) UnhandledPromiseRejectionWarning: Error: Incorrect login details were provided.
at WebSocketConnection.client.ws.connection.once.event (C:\Users\mort3\Desktop\Sakabato\node_modules\discord.js\src\client\ClientManager.js:48:41)
at Object.onceWrapper (events.js:276:13)
at WebSocketConnection.emit (events.js:188:13)
at WebSocketConnection.onClose (C:\Users\mort3\Desktop\Sakabato\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:390:10)
at WebSocket.onClose (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\event-target.js:124:16)
at WebSocket.emit (events.js:188:13)
at _receiver.cleanup (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\websocket.js:220:12)
at Receiver.cleanup (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\receiver.js:535:15)
at WebSocket.finalize (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\websocket.js:206:20)
at TLSSocket.emit (events.js:193:15)
(node:800) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:800) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Double check if you have copied the token from the Bot tab, not from General Information tab.

The discord API and discord.js (which is a wrapper for the discord api) require an authentication token. You supply this token on login:
client.login(<insert your token here>)
You are not replacing the filler text your-token-goes-here with your actual authentication token, one that you receive by making an application on discord (See https://discordjs.guide/#/preparations/setting-up-a-bot-application)
To see how I got here, look at the stack trace, the error message:
Error: Incorrect login details were provided.
It's pretty self-evident what the error is; in this case, you didn't supply any login details.

It says
Error: Incorrect login details were provided
You need to get a bot token via the Discord Developer Dashboard, create an application there, convert it to a Bot account and from there you can get the needed token to use in the client.loginmethod.
Make sure to never show anyone this token.

you need to create a token for the bot to connect with the Discord API

Related

In my bot I'm using my command bot info or my bot joins new guild it getting errors to send the message

When ever I'm using my bot info command it showing this error and i don't know how to solve it
Error
TypeError: Cannot read properties of null (reading 'broadcastEval')
at module.exports (/home/container/src/commands/bot/info.js:7:22)
at Client.client.loadSubcommands (/home/container/src/handlers/functions/functions.js:87:130)
at processTicksAndRejections (node:internal/process/task_queues:96:5)```

How do I resolve the 50001-Error "Missing Access" when trying to register commands for my bot?

I am having some trouble with the registration of commands for my Discord bot.
I am following the tutorial on discordjs.guide, but get an error, where they dont. When I try to run their code, I get an error in the console related to missing access of the bot. I am aware that "applications.commands" needs to be checked in the discord developer portal and that the bot needs to be kicked and re-added to the server, but despite doing all that, the error still remains.
The error looks like this:
DiscordAPIError[50001]: Missing Access
at SequentialHandler.runRequest (<my-folder-path>\node_modules\#discordjs\rest\dist\index.js:753:15)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (<my-folder-path>\node_modules\#discordjs\rest\dist\index.js:565:14)
at async REST.request (<my-folder-path>\node_modules\#discordjs\rest\dist\index.js:999:22) {
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'PUT',
url: 'https://discord.com/api/v9/applications/<my-bot-id>/guilds/<my-guild-id>/commands',
requestBody: { files: undefined, json: [ [Object], [Object], [Object] ] }
}
I have replaced a few irrelevant parts in the message like Ids and folder paths with general statements at "< >" due to privacy reasons.
On thing that differs from the error-message of some other folks with the same problem, is that there is no line in their message stating the request-body like there is in the last line of mine.
The issue could be resolved by adding the "application.commands" permission in the bot settings, but as stated earlier, this didnt work for me. In terms of code, I am using the exact code as in the example, with my specific data filled into the config.json.
My bot has the scopes of "bot" and "application.commands", as well as the bot permissions of "Administrator".
I am very thankful for every response!
Check if the applications.commands scope is checked in the developers portal OAuth2 section.

Cannot read property 'substring' of undefined Error in React when adding Social sign-in (OAuth) with AWS Amplify

I'm working with ReactJs and trying to add Social sign-in using AWS Amplify, i follow all the steps (provide the redirect signin/signout URI, Google Web Client ID and secret for my OAuth) and then this error shows.
TypeError: Cannot read property 'substring' of undefined
at userPoolDefaults (C:\Users\dell\AppData\Roaming\npm\node_modules\#aws-amplify\cli\node_modules\amplify-category-auth\src\provider-utils\awscloudformation\assets\cognito-defaults.js:24:47)
at Object.identityAndUserPoolDefaults [as identityPoolAndUserPool] (C:\Users\dell\AppData\Roaming\npm\node_modules\#aws-amplify\cli\node_modules\amplify-category-auth\src\provider-utils\awscloudformation\assets\cognito-defaults.js:66:6)
at C:\Users\dell\AppData\Roaming\npm\node_modules\#aws-amplify\cli\node_modules\amplify-category-auth\src\provider-utils\awscloudformation\utils\auth-defaults-appliers.ts:46:54
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at C:\Users\dell\AppData\Roaming\npm\node_modules\#aws-amplify\cli\node_modules\amplify-category-auth\src\provider-utils\awscloudformation\handlers\resource-handlers.ts:39:31
at Object.executeAmplifyCommand (C:\Users\dell\AppData\Roaming\npm\node_modules\#aws-amplify\cli\node_modules\amplify-category-auth\src\index.js:379:3)
at executePluginModuleCommand (C:\Users\dell\AppData\Roaming\npm\node_modules\#aws-amplify\cli\src\execution-manager.ts:175:3)
at Object.executeCommand (C:\Users\dell\AppData\Roaming\npm\node_modules\#aws-amplify\cli\src\execution-manager.ts:28:5)
at Object.run (C:\Users\dell\AppData\Roaming\npm\node_modules\#aws-amplify\cli\src\index.ts:146:5)
There was an error adding the auth resource
In my case the error occurred because I moved the entire repo folder to another place, I corrected it by returning the folder to where it had it.
I discovered it because I tried to amplify pull to see if it would be corrected, and I got an error that it could not find team-provider-info.json, being that if it was there, until I notice that the path where I was looking for it was where it had before file

How can I fix the "Unhandled Rejection (error): Network error" obtained using axios in React

I'm creating a React Application, and it is hosted on localhost:3000. I want to fetch data from a .NET Core Application hosted on localhost:5001. I'm using axios library to make http requests.
The function in which I make the request is:
async componentDidMount() {
const data = await axios.get("http://localhost:5001/api/gateways");
console.log(data);
}
The obtained Error is "Unhandled Rejection (Error): Network Error".
I tried to test the API with Postman and it works, as well as accessing it from the browser and it works too.
At the same time I tried to consume data from another API, this time hosted on an online server, and it worked perfectly, that means, the problem must be between two applications hosted on the localhost.
I fixed this issue by adding an Access-Control-Allow-Credentials header to HTTP responses in .NET CORE application. This header tells the browser that the server allows credentials for a cross-origin request.
Its necessary modify Configure method at Startup.cs fileadding the following code:
app.Use(async (context, next) =>
{
context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
await next.Invoke();
});
And, it is also necessary modify ConfigureServices method with:
services.AddCors(c =>
{
c.AddDefaultPolicy(options => options.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod());
});

React Axios error doesnt actually get resolved, it gets an error creating the error

Im building a react app with a spring boot server and when i log in with password right, it comes 200 all works, but when i miss the password on purpose to test what happens, Axios does't parse the error.
It says:
Error: Request failed with status code 403
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:61)
and the actual error occurs here
export async function login(login: Credentials) {
try {
const result = await axios.put(base + 'user', login)
return result
} catch (err) {
--> console.log(err)
return err
}
}
The error occurs in the console.log, telling me it detected it was not a code 200 therefore it blew up there but it cant actually resolve the error?
Im quite lost with this, ive use axios for ages and this never happened.
I ve also deployed the server to Azure to not put the server and website in the same machine cuz cors but nothing helped.
Any thoughts?
Okay, I made a silly mistake. In the request function i do return err.response instead of THROW err.response
Thats how it passes to be a rejected promise instead of fullfilled. Sorry.

Resources