How to change server vanity url with discord.js - discord

As it says in the title, how can I change it with discord.js? I want to change using api v8 or using discord bot.

Unfortunately, because only guilds with level 3 can set a vanity URL, you can only set a vanity URL through the official Discord app. However you can recieve a guilds vanity URL with the following link: https://discord.com/api/v8/guilds/{guild-id}/vanity-url. Assuming your bot has MANAGE_GUILD permissions and you define the Authorization header.

Related

How do you create a redirect URI?

So, a redirect URI is required to invite your Discord bot to your server. However, I tried using this as my redirect URI (replacing CLIENTID with my bot's client ID) and it didn't work:
https://discordapp.com/oauth2/authorize?&client_id=%5BCLIENTID%5D&scope=bot
It says "CLIENT ID is not a snowflake" after trying to invite my bot. How do I fix this, as I've looked everywhere with no good solutions.

Can you use the Discord API to get what servers the bot is in, and How?

Im trying to make a discord dashboard all out of Pure HTML (Includes JS, CSS just to be clear), and I wanted to get a list of all the guilds the bot is in without any other APIs like discord.py or discord.js.
How can I do this? I couldn't find anything on the Discord Developer Documentation, and is it even possible?
I've tried some answers like getting '/users/#me/guilds', but it just returns the current person that is logged in with the bot's guilds, and not what the bot has joined.
Thanks.
You should make an HTTP requests with your bot's token:
URL: https://discord.com/api/v9/users/#me/guilds
HEADERS: Authorization: "Bot TOKEN"
It will return a JSON with all the guilds your bot is in.
But make sure you don't leak your bot's token somewhere in JS or HTML files.
I guess this should work, have a good day! :D

Discord API: View guild channels information with Oauth2 guilds scope

I am trying to make a call to /guilds/guild.id/channels endpoint after retrieving a user's guild data that is provided after they successfully authenticate with my app using the Discord's OAuth flow.
My OAuth permissions include email and guilds.
After receiving an access_token I am able to make a call to /users/#me/guilds. However, when I try to iterate over this to access each guild's list of channels using the /guilds/guild.id/channels endpoint I receive a {"message": "401: Unauthorized", "code": 0}. I pass the same access_token in the header of this request.
My question is about the limitations of the Discord API when authenticating with OAuth. The documentation says
Unlike the normal OAuth2 flow, bot accounts have full access to all API routes without using bearer tokens
So can I make an API call to /guilds/guild.id/channels using my access_token?
Or do I have to do this through a bot? And if a bot is required then that means in order to make a call to /guilds/guild.id/channels the bot must first be added to the guild, right?
I believe you falsely assumed that the guilds OAuth2 scope will give you full access to the guilds of the user. This is not the case, the guilds scope only grants the access token permission to view a list of all the user's guilds and basic information of these guilds (guild ID, avatar, name, flags, the user's permission, and whether the user's the owner).
This does not include giving you access to see the guild's channels. The only endpoint guilds scope gives you is /users/#me/guilds which you already know. I believe this is due to user privacy concerns since it unnecessarily lets you to view the channels list from non-related guilds. Most cases when the guilds scope is used, it is to verify if the user's in a certain guild; useful for bot dashboards.
The only way to retrieve a list of channels requires you to have a bot in the guild and use the /guilds/<guild.id>/channels while identifying as your bot.
To see what the OAuth2 scopes actually grants you, it's documented here: https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes.

Use Discord's API to send message as user

I want to send a message in a Discord channel but from a user account not a bot. Is this kind of thing possible using Discord's API?
The official documentation should contain enough information to get started: https://discord.com/developers/docs/resources/channel#create-message
Make sure to login with OAuth2 and not as a bot. Also, it is important to get the right scope (permissions) when requesting an OAuth token.

Is it possible to find out what discord bot a token belongs to?

I got multiple discord bots and sometimes it would be useful to find out to what bot a token belongs to via the API or some other way?
I'm using Javachord and I've found there's a getYourself() in DiscordApi that returns a User which represents the current bot.
I'm not sure how that maps to the Discord API itself though
Here's an alternative solution.
Discord has an API endpoint users/#me that returns the current user's user object.
Try this for an example:
curl -H "Authorization: Bot <token>" https://discord.com/api/v9/users/#me
Discord also sends back a user object (part of lots more info) as part of the Identify process when using its websocket gateways, but this probably isn't what you would want.

Resources