Trying to register commands: DiscordAPIError[50001]: Missing Access - javascript

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!

Related

Provided Address is invalid, the capitalization checksum test failed

I am trying to send a method on a contract using web3. I'm creating an account using the privateKeyToAccount method but when sending the method on the contract I get the following error:
Provided address [object Object] is invalid, the capitalization checksum test failed, or it's an indirect IBAN address which can't be converted.
Am I missing a step? I already created an instance of web3 and the contract interface works. I attached part of the code below. Thanks in advance for the help.
const web3 = new Web3(
new Web3.providers.WebsocketProvider(
'wss://rinkeby.infura.io/ws/v3/<api>'
)
);
const dummyPrivateKey = '0x38544e1555a3553829219281253d2400fa20ebbd922fdh3918a7s2b53b9e1358';
const accounts = web3.eth.accounts.privateKeyToAccount(dummyPrivateKey);
await contract.methods // add username
.addMessage(_username, _message)
.send({ from: accounts });
Petr is right. I missed the part where you are giving the whole object instead of address.
But if you want to checksum an address. You can simply use Web3 utility function web3.utils.toChecksumAddress(address) to convert. More details here
You're passing the account object to the from field. But you need to pass just the address.
Replace the from: accounts to from: accounts.address.
Note: This is how the accounts object looks like:
{
address: '0x29B67BB1cFE4799FDb46B49aD81cD771665E2dF7',
privateKey: '0x38544e1555a3553829219281253d2400fa20ebbd922fdh3918a7s2b53b9e1358',
signTransaction: [Function: signTransaction],
sign: [Function: sign],
encrypt: [Function: encrypt]
}
Ensure that the address that you are providing is valid. You can get the address from either online providers like Infura or local setup like Ganache.
If still an issue persists, then try to use the following code.
web3.utils.toChecksumAddress(address)
I also encountered this problem in the project, but in my case, I also used Web3 service and same test network at the same time. Stop another service and back to normal now.

How to send a message to another Discord server on a specific channel? [duplicate]

I'm failing to achieve something very simple. I can't send a message to a specific channel. I've browsed trough the documentation and similar threads on stack overflow.
client.channels.get().send()
does NOT work.
It is not a function.
I also do not see it as a method on the Channel class on the official documentation yet every thread I've found so far has told me to use that.
I managed to have the bot reply to a message by listening for a message and then using message.reply() but I don't want that. I want my bot to say something in a specific channel in client.on('ready')
What am I missing?
You didn't provide any code that you already tested so I will give you the code for your ready event that will work!
client.on('ready', client => {
client.channels.get('CHANNEL ID').send('Hello here!');
})
Be careful that your channel id a string.
Let me know if it worked, thank you!
2020 Jun 13 Edit:
A Discord.js update requires the cache member of channels before the get method.
If your modules are legacy the above would still work. My recent solution works changing the send line as follows.
client.channels.cache.get('CHANNEL ID').send('Hello here!')
If you are using TypeScript, you will need to cast the channel in order to use the TextChannel.send(message) method without compiler errors.
import { TextChannel } from 'discord.js';
( client.channels.cache.get('CHANNEL ID') as TextChannel ).send('Hello here!')
for v12 it would be the following:
client.on('messageCreate', message => {
client.channels.cache.get('CHANNEL ID').send('Hello here!');
})
edit: I changed it to log a message.
This will work for the newest version of node.js msg.guild.channels.cache.find(i => i.name === 'announcements').send(annEmbed)
This should work
client.channels.fetch('CHANNEL_ID')
.then(channel=>channel.send('booyah!'))
Here's how I send a message to a specific channel every time a message is deleted. This is helpful if you'd like to send the message without a channel ID.
client.on("messageDelete", (messageDelete) => {
const channel = messageDelete.guild.channels.find(ch => ch.name === 'channel name here');
channel.send(`The message : "${messageDelete.content}" by ${messageDelete.author} was deleted. Their ID is ${messageDelete.author.id}`);
});
Make sure to define it if you're not using messageDelete.

Error: AADSTS500011: The resource principal named "URL" was not found in the tenant

I am trying to add an app to our SharePoint Online site using the template from https://learn.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/get-started/build-a-hello-world-web-part and we get the error below when we deploy to SharePoint and add the app/Web part to a test SharePoint site. We are using TypeScript as the template uses.
Has anyone else encountered this issue or know where to look for the issue?
Found [object Object]Driver Display External Error: Error: AADSTS500011: The resource principal named https://driverdisplayexternal.azurewebsites.net was not found in the tenant named 7018324c-9efd-4880-809d-b2e6bb1606b6. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You might have sent your authentication request to the wrong tenant. Trace ID: 358b22eb-cd2c-4091-b592-5a57cbc21d00 Correlation ID: ec96d656-1a36-42e2-a2b9-3ff78efc1e2e Timestamp: 2019-10-01 16:26:06Z
We have added a call to our own client as shown below. We are not sure why the resource principal was not found. The Tenant ID's match and things seem to be set up properly for authentication.
HelloWorldWebPart.ts
...
this.context.aadHttpClientFactory
.getClient('https://driverdisplayexternal.azurewebsites.net')
.then((client: AadHttpClient): void => {
client
.get('https://driverdisplayexternal.azurewebsites.net/api/values', AadHttpClient.configurations.v1)
.then((response: HttpClientResponse): Promise < Order[] > => {
this.domElement.innerHTML += 'Received a response from Driver Display External: ' + response;
return response.json();
})
.catch(error => {
this.domElement.innerHTML += 'Driver Display External Error: ' + error;
console.error(error);
});
});
...
package-solution.json
{
"$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": {
"name": "helloworld-webpart-client-side-solution",
"id": "**ID**",
"version": "4.1.0.0",
"includeClientSideAssets": true,
"isDomainIsolated": false,
"webApiPermissionRequests": [
{
"resource": "DriverDisplayExternal",
"scope": "User.Read.All"
}
]
},
"paths": {
"zippedPackage": "solution/helloworld-webpart.sppkg"
}
}
Any help or direction to where the issue may be would be very appreciated. Thanks in advance!
Never used this API, but if I had to guess you need to change the value here:
.getClient('https://driverdisplayexternal.azurewebsites.net')
You can use either the client id / application id, or the application ID URI.
Sometimes this problem can occurr when you set a wrong name for the scope you are requesting access for or another configuration parameter.
I suggest to check carefully the scopes name, or maybe directly use the "copy" button from the Azure portal.
In my case it was a simple typo on a scope name.
Not sure if you figured the answer or not. When you used SPFx to request your own custom web api end point. there are couple steps:
request the permission so that you can go to SPO admin to approve the permission you request. for this case, the webApiPermissionRequests->resources needs to your AAD Application's Service Principal DisplayName. once you had AAD App create, you can run Get-AzureADServicePrincipal to get all your ServicePrincipal.
once you request the permission, from your code, you need to call AadHttpClient.getClient() to get aadHttpClient object based on the api resourceEndpoint you want, for this case, you need to pass your web api's Application ID URI which can be found from your AAD App's manifest->"identifierUris". General speaking, this should be something like api://[clientid] format. but you can change it to any unique value.
I hope it helps.
In my case i had to use the App Id when i was consuming a multi tenant API.
In my case, TenantId and ClientId were both ok.
They can be found in AAD. TenantId is right there on landing page:
and then on the same page click Applications then tab All Applications find your application there should be ClientId check if they match.
If that is still not enough, click on the application and find roles
For me, it was roles that were missing after adding those wheels started rolling again:

JavaScript runtime error: [Messenger] Required property 'target' was not provided occurred

I am using the Developers API with an App I created in LinkedIn.
When I call this method to sign in.....
IN.UI.Authorize().params({ "scope": ["r_liteprofile", "r_emailaddress"] }).place()
a Window begins to open and I get this error message:
Unhandled exception at line 7, column 56783 in
http://platform.linkedin.com/in.js 0x800a139e - JavaScript runtime
error: [Messenger] Required property 'target' was not provided
occurred
I have completed LinkedIn's App Setup, but can't figure what could be causing this. My JavaScript code is below:
[script type="text/javascript" src="//platform.linkedin.com/in.js"]
api_key: 'xxxxx......xxxxx'
authorize: true
[/script]
function LinkedInSignIn() {
IN.UI.Authorize().params({ "scope": ["r_liteprofile", "r_emailaddress"] }).place();
IN.Event.on(IN, 'auth', getProfileData);
}
function getProfileData() { // Use the API call wrapper to request the member's basic profile data
IN.API.Profile("me").fields("id,firstName,lastName,email-address,picture-urls::(original),public-profile-url,location:(name)").result(function (me) {
var profile = me.values[0];
var id = profile.id;
alert(profile.firstName);
});
}
As it turned out, the reason this is not working is becuase LinkedIn discontinued it at the end of 2018. Contacting LinkIn's support wasn't much help either. They only said they do no support thier code library and referred my back here to StackOverflow.
For anyone having the same problem, the solutions is to use Oauth2, which is documented at:
https://learn.microsoft.com/en-us/linkedin/shared/authentication/authorization-code-flow?context=linkedin/context
Happy Coding!
Graham

Javascript Buy SDK - Error: Not Found

I'm trying to retrieve products from my Shopify store with this code, a near copy/paste of the examples page for the Javascript Buy SDK:
$(function() {
var shopClient = ShopifyBuy.buildClient({
accessToken: '4b4e3d4bba63039f2d51db94c2e79a46',
domain: 'squatch-air-clutches-test.myshopify.com',
appId: '6'
});
shopClient.fetchQueryProducts({
collection_id: 1397227547
}).then(function(products) {
$('.test').append(JSON.stringify(products));
});
shopClient.fetchProduct('46656520219').then(function(product) {
$('.test').append(JSON.stringify(product));
});
});
Here's a fiddle.
The buildClient command seems to complete successfully, however I get a console error with the next two commands: Error: Not Found. I assume this refers to the product not able to be found, but I am sure both the product and the collection ids are correct. And I am also sure that I have read access enabled for "products, variants, and collections" for my private app. Would there be any other reason I am getting this error, and if so, what's a solution?
Got it. The App ID was incorrect. I needed to go to /admin/settings/storefront_access_tokens and grab the correct ID for my sales channel. I'm disappointed that it was so difficult to find though - the documentation on this seems convoluted.

Categories