I am making a Serverinfo command on my bot. So i want add the server info command show the guild's vanity too! But I read the whole discord documentation but can't find how can i make the bot detect the vanity url and sends it. Then I tried to test by making that command as a single command. Here is my code:
#bot.command()
async def vanity(ctx):
vanity = str(ctx.guild.vanity_url)
await ctx.send(vanity)
The bot doesn't response with the code. A help will be appreciated. Thanks in advance.
Try this to get the vanity url:
vanity = (await ctx.guild.vanity_invite()).url
Documentation reference: https://discordpy.readthedocs.io/en/stable/api.html#discord.Guild.vanity_invite
Related
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
I have a Discord bot added to a few servers/guilds. I'm able to get a specific guild using the resources available here:
https://discord.com/developers/docs/resources/guild
It's fairly simple, requiring me to send a GET request to https://discordapp.com/api/guilds/{guildID}. What I want to do is get a list of all the guilds that my bot is connected to using the API. Haven't been able to find anything referencing that in the docs. Is this possible to do?
For sure it's possible, you can directly interect with the API like this:
fetch('https://discordapp.com/api/users/#me/guilds', {
headers: {
'Authorization': token
}
});
Also, you can find the documentation on https://discord.com/developers/docs/resources/user#get-current-user-guilds
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.
I want to send an embed in discord, and then store the message link of the embed in a database. But in order to do that, I need a way to access the link to the embed. Is there any way to get the message link of a MessageEmbed object in discord.js? I've looked through the discord.js docs but I couldn't find anything.
You can use message.url to get the URL for a message
If your bot sends a message it can be used like this
channel.send(embed).then(embedMessage => {
const url = embedMessage.url
// add to url database
});
I want to send a message from my discord bot to a specific user like myself using my discord id.
I have tried the following code where my client object is named as bot:
bot.users.get("My Id copied from discord").send("Message to Send");
but it gives the following error in the terminal:
bot.users.get is not a function
Please help me in resolving this error.
Thank you
Since discord.js v12 you need to use cache to access the users collection
bot.users.cache.get('ID').send('hello')
You need to use users.fetch() instead since the user might not be cached
const user = await bot.users.fetch('ID')
user.send('hello')