|
| 1 | +# API example for discord bot |
| 2 | + |
| 3 | +This is an example to get random images or videos for your discord bot |
| 4 | + |
| 5 | +## Usage |
| 6 | + |
| 7 | +### For discord bot written in python |
| 8 | + |
| 9 | +For the images/videos |
| 10 | +```py |
| 11 | +def genshin(): |
| 12 | + response = requests.get('https://api.pellinuz.repl.co/api/type=genshin') |
| 13 | + if response.status_code == 200: |
| 14 | + image_url = response.json()['message'] |
| 15 | + image_url = random.choice("message") |
| 16 | + else: |
| 17 | + print('Error getting random image') |
| 18 | + return image_url |
| 19 | +``` |
| 20 | + |
| 21 | +For the color |
| 22 | +```py |
| 23 | +def embedColor(): |
| 24 | + response = requests.get('https://api.pellinuz.repl.co/api?type=genshin') |
| 25 | + if response.status_code == 200: |
| 26 | + color = int(response.json()['color'], 16) |
| 27 | + embed_color = discord.Color(color) |
| 28 | + else: |
| 29 | + print('Error getting random color') |
| 30 | + embed_color = discord.Color.default() |
| 31 | + return embed_color |
| 32 | +``` |
| 33 | + |
| 34 | +Define the functions |
| 35 | +```py |
| 36 | +genshin_images = genshin() |
| 37 | +color_embed = embedColor() |
| 38 | +``` |
| 39 | + |
| 40 | +Command example |
| 41 | +```py |
| 42 | +@client.slash_command(name="image", description="Random Image") |
| 43 | +async def image(ctx): |
| 44 | + await ctx.respond(genshin()) |
| 45 | +``` |
| 46 | + |
| 47 | +### For discord bot written in js |
| 48 | + |
| 49 | +For the images/videos |
| 50 | +```js |
| 51 | +async function genshin() { |
| 52 | + const response = await fetch('https://api.pellinuz.repl.co/api?type=genshin'); |
| 53 | + if (response.ok) { |
| 54 | + const image_url = (await response.json()).message; |
| 55 | + return image_url; |
| 56 | + } else { |
| 57 | + console.log('Error getting random image'); |
| 58 | + } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +For color |
| 63 | +```js |
| 64 | +async function embedColor() { |
| 65 | + const response = await fetch('https://api.pellinuz.repl.co/api?type=genshin'); |
| 66 | + if (response.ok) { |
| 67 | + const color = parseInt((await response.json()).color, 16); |
| 68 | + const embedColor = new Discord.MessageEmbed().setColor(color); |
| 69 | + return embedColor; |
| 70 | + } else { |
| 71 | + console.log('Error getting random color'); |
| 72 | + const embedColor = new Discord.MessageEmbed().setColor('DEFAULT'); |
| 73 | + return embedColor; |
| 74 | + } |
| 75 | +} |
| 76 | +``` |
| 77 | + |
| 78 | +NOTE: if the js codes isn't right it isn't my problem, it has been conveted using ChatGPT |
| 79 | + |
| 80 | +## HOST |
| 81 | + |
| 82 | +[](https://replit.com/new/github/pellinuz/api) |
0 commit comments