Guest User

Untitled

a guest
Jun 4th, 2026
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. const google = require('@googleapis/drive');
  2.  
  3. const { google_key, client_email, folderId } = require('../../config.json');
  4. const { AttachmentBuilder, SlashCommandBuilder } = require('discord.js');
  5.  
  6. // if you steal my credentials i will KILL MYSELF
  7. const auth = new google.auth.GoogleAuth({
  8. credentials: {
  9. client_email: client_email,
  10. private_key: google_key.replace(/\\n/g, '\n'),
  11. },
  12. scopes: ['https://www.googleapis.com/auth/drive.readonly'],
  13. });
  14.  
  15. // random oso from drive
  16. async function getRandomOso() {
  17. const drive = google.drive({ version: 'v3', auth });
  18. try {
  19. // Fetch all files inside the specific folder that are images or videos
  20. const response = await drive.files.list({
  21. q: `'${folderId}' in parents and (mimeType contains 'image/' or mimeType contains 'video/') and trashed = false`,
  22. fields: 'files(id, name, webContentLink, thumbnailLink)',
  23. pageSize: 500,
  24. });
  25.  
  26. const files = response.data.files;
  27.  
  28. if (!files || files.length === 0) {
  29. console.log('No images found in this folder.');
  30. return null;
  31. }
  32.  
  33. // Pick a random file from the array
  34. const randomIndex = Math.floor(Math.random() * files.length);
  35. const randomImage = files[randomIndex];
  36.  
  37. return randomImage;
  38.  
  39. }
  40. catch (error) {
  41. console.error('Error fetching files from Google Drive:', error);
  42. }
  43. };
  44. module.exports = {
  45. data: new SlashCommandBuilder().setName('oso').setDescription('oso'),
  46. async execute(interaction) {
  47. await interaction.reply(
  48. new AttachmentBuilder(getRandomOso().webContentLink),
  49. );
  50. },
  51. };
Advertisement
Add Comment
Please, Sign In to add comment