Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const google = require('@googleapis/drive');
- const { google_key, client_email, folderId } = require('../../config.json');
- const { AttachmentBuilder, SlashCommandBuilder } = require('discord.js');
- // if you steal my credentials i will KILL MYSELF
- const auth = new google.auth.GoogleAuth({
- credentials: {
- client_email: client_email,
- private_key: google_key.replace(/\\n/g, '\n'),
- },
- scopes: ['https://www.googleapis.com/auth/drive.readonly'],
- });
- // random oso from drive
- async function getRandomOso() {
- const drive = google.drive({ version: 'v3', auth });
- try {
- // Fetch all files inside the specific folder that are images or videos
- const response = await drive.files.list({
- q: `'${folderId}' in parents and (mimeType contains 'image/' or mimeType contains 'video/') and trashed = false`,
- fields: 'files(id, name, webContentLink, thumbnailLink)',
- pageSize: 500,
- });
- const files = response.data.files;
- if (!files || files.length === 0) {
- console.log('No images found in this folder.');
- return null;
- }
- // Pick a random file from the array
- const randomIndex = Math.floor(Math.random() * files.length);
- const randomImage = files[randomIndex];
- return randomImage;
- }
- catch (error) {
- console.error('Error fetching files from Google Drive:', error);
- }
- };
- module.exports = {
- data: new SlashCommandBuilder().setName('oso').setDescription('oso'),
- async execute(interaction) {
- await interaction.reply(
- new AttachmentBuilder(getRandomOso().webContentLink),
- );
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment