Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { ApplicationCommandType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ApplicationCommandOptionType } = require('discord.js');
- const { Client, GatewayIntentBits, Partials, Collection } = require('discord.js');
- const { Configuration, OpenAIApi } = require('openai')
- const client = new Client({
- intents: [
- GatewayIntentBits.Guilds,
- GatewayIntentBits.GuildMessages,
- GatewayIntentBits.MessageContent,
- GatewayIntentBits.GuildMembers,
- GatewayIntentBits.GuildBans,
- GatewayIntentBits.DirectMessageReactions,
- GatewayIntentBits.DirectMessageTyping,
- GatewayIntentBits.DirectMessages,
- GatewayIntentBits.GuildEmojisAndStickers,
- GatewayIntentBits.GuildIntegrations,
- GatewayIntentBits.GuildInvites,
- GatewayIntentBits.GuildMembers,
- GatewayIntentBits.GuildMessageReactions,
- GatewayIntentBits.GuildMessageTyping,
- GatewayIntentBits.GuildMessages,
- GatewayIntentBits.GuildPresences,
- GatewayIntentBits.GuildScheduledEvents,
- GatewayIntentBits.GuildVoiceStates,
- GatewayIntentBits.GuildWebhooks
- ],
- partials: [Partials.Channel, Partials.Message, Partials.User, Partials.GuildMember, Partials.Reaction]
- });
- const configuration = new Configuration({
- apiKey: process.env.CHATGPTKEY
- });
- const openai = new OpenAIApi(configuration);
- module.exports = {
- name: 'ask-gpt',
- description: "Ask ChatGPT (3.0) a question!",
- type: ApplicationCommandType.ChatInput,
- cooldown: 3000,
- options: [
- {
- name: 'prompt',
- description: 'The question you would like to ask.',
- type: ApplicationCommandOptionType.String,
- required: true
- }
- ],
- run: async (client, interaction) => {
- const user = interaction.user;
- const question = interaction.options.getString('prompt')
- await interaction.deferReply();
- try {
- const res = await openai.createCompletion({
- model: 'text-davinci-003',
- maxtokens: 2046,
- temperature: 0.5,
- prompt: question
- })
- const embed = new EmbedBuilder()
- .setDescription(`\`\`\`${res.data.choices[0].text}\`\`\``)
- await interaction.editReply({embeds: [embed] });
- } catch (e) {
- return await interaction.editReply({content: `Request failed with status code **${e.response.status}**`, ephemeral: true })
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement