What is the reason behind this error?
this code I am using to connect to DB.
const uri =`mongodb+srv://${process.env.DB_USER}:${process.env.DB_PASSWORD}#cluster0.xft2s.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`;
Check if you have access to your env contents first, by adding this line console.log(process.env.DB_USER, process.env.DB_PASSWORD).
Related
I am building a webrtc system and currently trying to have the session description sent back to the local connection. Below is the code block I am using to have the session description reinserted on the local side, but I am getting the error below. The "lc.setRemoteDescription()" line works when I manually type the description into lc.setRemoteDescription() in the devtool console. Any ideas what this could be due to?
Javascript code
...
console.log("broadcastlist");
broadcastlist.push(data.message);
console.log(data.message);
connectcounter ++;
console.log(connectcounter)
var user = data.user
var csrftoken = $("[name=csrfmiddlewaretoken]").val();
lc.setRemoteDescription(data.message)
...
Output on browser dev tools console. ("lc.setRemoteDescription(data.message)" corresponds to the error displayed in the picture below.
That error happens when you attempt to pass a string to setRemoteDescription:
const pc = new RTCPeerConnection();
pc.setRemoteDescription("")
Assuming that your data.message is a JSON-serialized object you need to convert it to an object with JSON.parse first.
Following this; https://discordjs.guide/creating-your-bot/creating-commands.html#command-deployment-script
I'm trying to run node deploy-commands.js to register my commands to a single guild and I'm getting the following error.
C:\Users\\\\hello-world-discord-bot>node deploy-commands.js
DiscordAPIError[50001]: Missing Access
at SequentialHandler.runRequest (C:\\\\\hello-world-discord-bot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.js:198:23)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.queueRequest (C:\\\\\hello-world-discord-bot\node_modules\#discordjs\rest\dist\lib\handlers\SequentialHandler.js:99:20)
at async C:\\\\\hello-world-discord-bot\deploy-commands.js:17:3 {
rawError: { message: 'Missing Access', code: 50001 },
code: 50001,
status: 403,
method: 'put',
url: 'https://discord.com/api/v9/applications/877359061669118003/guilds/447125601757691915/commands'
}
I've tried removing the bot and re-permissioning it via the developer web console before re-adding it. I've checked and re-added the token clientId and guildId and I get the same error message every time. I can see it's not getting access but I've no idea where else access would be granted from.
My deploy-commands.js looks like this:
{
"clientId": "123456789012345678",
"guildId": "876543210987654321",
"token": "my-token-goes-here"
}
Have you made sure that the 'applications.commands' scope is checked in the scopes section of the OAuth2 settings for your bot in the discord developer portal?
jh316's answer works with the additional context, for us noobs, that checking that box also requires copying the URL, pasting it in a browser so that you can access the authentication page where you get to choose the Discord server the authorization will apply to...and then click 'Authorize' in order to complete the authorization. Then running the deploy-commands.js script will run successfully.
Although I had checked 'applications.commands' it would still not work for me.
The solution was quite simple,
I had copied the id of a text channel when I should have copied the server's id.
I stumbled into this error, in my case the issue was guildId being a number and not a string.
If some one has the related problem =>
1/ Check your developer Page if the Plugin 'applications.commands' at OAuth2 settings checked!
2/ If still not work, just re-invite the bot and haveit "USE SLASH COMMANDS" Permission!
I am getting the following error when trying to run my server (index.js):
Error: TypeError [ERR_INVALID_URL]: Invalid URL: index.js
The code block is here:
app.get('/:url', async function (req, res) {
try {
return res.status(200).json(data);
} catch (ex) {
console.log(ex);
return res.status(500).json({ message : "Oops." });
}
With the specific line of code it is referring to is:
const site = await .open(decodeURIComponent(req.params.url));
Has anyone ever encountered this error before, and have any idea how to fix it in this context? Not sure how it is throwing an error for my entire index.js server
Note: This is an express app
The value of req.params.url is index.js.
A web browser can expand index.js into an absolute URL because it knows that it can use the URL of the current HTML document as the base URL.
You're running your code in Node.js. It doesn't run inside a document. There is no base URL.
You need to provide an absolute URL (e.g. http://example.com/index.js) yourself.
That said, I suspect wappalyzer may require that you give it the URL to an HTML document not a JS file.
Well, since there isn't much that i can see about your usage, I'm just going to assume you went to something like http://localhost/index.js.
The problem now is, that wappalyzer does not actually get a valid url. It gets index.js without any form of protocol (http/https/ws/wss...). This means it doesn't know what to do and tells you that the url you provided is invalid.
In order to fix this go to http://localhost/https%3A%2F%2Flocalhost%2Findex.js or append https:// or something similar to your parameter.
I want to be able to read the client.login(BOT_TOKEN); dynamically from a file/database, but this is getting executed before my file read function finishes executing.
BOT_TOKEN = '';
if(BUILD_PROFILE == 'dev'){
filesystem.readFile('./../devToken.txt', 'utf8', (err, data) => {
if(err) throw err;
console.log(data);
BOT_TOKEN = data;
})
}
client.login(BOT_TOKEN);
This is the error I'm getting in logs - I have double checked the file and it's console.log(data) shows the right token, but it's not being applied
I suggest you place your token in an ENV file.
I also think you should copy your token directly from your bot's bot page on discord and pasting it directly.
You console.log'd the data was it the right token?
A very easy way to do this would be to have a config.js file in your main bot folder, and set out the
{
token: “token-here”
}
Then, in your main.js file, require the config file as a variable, then at your ‘bot.login’, just do ‘bot.login(config.token)’
You can also have your prefix set in this file too, allowing a user to possibly change your command prefix in the future
Additionally, you could use a SQLite database, that saves your token - you have to have the SQLite npm library, from https://www.npmjs.com/package/sqlite here, but it is very simple to set up, if anyone needs help here, add my discord Proto#4992
n.m. SQLite databases also will come in useful when/if you want to set up a currency system in the future.
I am using async await in my nightwatch test. i am using expect assertion to validate the url. for some reasons its returning an error message. please find the code and an error message below. if anyone can help please ?
I have followed this document but not sure why failing- https://nightwatchjs.org/api/expect/#expect-url-
await browser.expect.url().to.contain(await `${data.Url}`);
returned error message as below
Error: Unknown property: "then". Please consult docs at: http://nightwatchjs.org/api.```
I found the issue in my code. The problem is , it didn't like await in the staring line of my code. once i removed that. it works wonderfully. here is the solution.
browser.expect.url().to.contain(await ${data.Url}).after(3000);