#Proper way to make Discord API requests

1 messages · Page 1 of 1 (latest)

karmic quail
#

Hello hello! b_wave2

I am trying to make requests to the Discord API, for example, getting information on a guild the user is in.

I can use the Python requests library, but this means no cooldown handling and all the cool interactions.py stuff.

import requests
def get_user_guild(guild_id: str):
    url = "https://discordapp.com/api/v6/guilds/"+ guild_id +"/preview"
    # we want a user token, because a bot token requires
    # said bot to be in the mentioned guild :(
    # not sure if that's nice! we don't want our users' tokens
    headers = {'Authorization': TOKEN}
    response = requests.get(url, headers=headers)

I know how to get guild info, but only if the bot is in it! This isn't very useful if the bot is only in a server or two.

from interactions import slash_command, slash_option, SlashContext, OptionType

@slash_command(name="get_server",
    description="Get info on a server")
@slash_option(name="server_id",
    description="ID of server to fetch",
    required=True,
    opt_type=OptionType.STRING)
async def cmd_get_user_guild(self, ctx: SlashContext, server_id: str):
    # this requires the bot to be in the guild :(
    guild = self.bot.get_guild(server_id)
    await ctx.send("This guild is: "+ guild.name)

Does interactions.py allow a better way to do this? Thank you for reading my silly issue!

torn veldtBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

still forum
#

Oh, is it self bot?

#

(user, which is controlled with code, but not official api (don't have APP thing))

karmic quail
#

Not yet! This is still a guild bot, although I do want to make it work both as a userbot and guildbot.

still forum
#

For example if I use this account to send messages with python, it's considered self bot

karmic quail
#

Oh! No no, it's a both with user install, not a userbot, I mean.

still forum
#

Oh, user install
Okay, uhm I don't remember if it's merged or not, give me a second

karmic quail
#

If this poses an issue, this question focuses mainly on a Guild install bot. The User install part is optional.

#

I have a suspicion I must use the interactions.py Gateway object, but am not sure how to.

still forum
#

I'm very confused rn, let me explain
User install and guild install basically use the same bot account
If you want command, which can be installed to user and used by him on any discord server, check this
There is also self-bots. Normal users (not apps) which are controlled with code. They were used long time ago (sometimes maliciously) and discord wanted to expand bot functionality in other directions, so they nuked any mention of them and rn they are haram. I.py and most libs don't support them, don't make them please

karmic quail
#

My question is, what is the intended way to make Discord API requests with interactions.py?
I know how to make prefixed and Slash commands. I am not making a self-bot, just a normal Discord bot.

still forum
#

Almost all i.py request functions are subclassed by HTTPClient

karmic quail
#

I will check this out, thank you! I'll close the issue as soon as I figure it out.