Created
September 17, 2024 19:46
-
-
Save nabeelxdd/ec00f9bf0a5f9f87f9bfcd4921dc4b43 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { bot } = require('../lib'); // Assuming your bot library is in ../lib | |
| async function getRandomImageURL() { | |
| const apiKey = "f6QueGeF_dxA2dyB71rlGVCgYzQ629A4ZvILHYJEFak"; | |
| try { | |
| const response = await fetch(`https://api.unsplash.com/photos/random?client_id=${apiKey}`); | |
| const data = await response.json(); | |
| return data.urls.regular; | |
| } catch (error) { | |
| console.error("Error fetching image:", error); | |
| return null; | |
| } | |
| } | |
| bot({ | |
| pattern: 'rndimg', | |
| desc: 'Sends a random image', | |
| type: 'media', | |
| }, async (message) => { | |
| const imageUrl = await getRandomImageURL(); | |
| if (!imageUrl) { | |
| return await message.send('Failed to fetch a random image.'); | |
| } | |
| await message.sendFromUrl(imageUrl, { buffer: false }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment