Advertisement
_______homie_______

Untitled

Feb 12th, 2023 (edited)
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. const { ApplicationCommandType, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ApplicationCommandOptionType } = require('discord.js');
  2. const { Client, GatewayIntentBits, Partials, Collection } = require('discord.js');
  3. const { Configuration, OpenAIApi } = require('openai')
  4.  
  5. const client = new Client({
  6. intents: [
  7. GatewayIntentBits.Guilds,
  8. GatewayIntentBits.GuildMessages,
  9. GatewayIntentBits.MessageContent,
  10. GatewayIntentBits.GuildMembers,
  11. GatewayIntentBits.GuildBans,
  12. GatewayIntentBits.DirectMessageReactions,
  13. GatewayIntentBits.DirectMessageTyping,
  14. GatewayIntentBits.DirectMessages,
  15. GatewayIntentBits.GuildEmojisAndStickers,
  16. GatewayIntentBits.GuildIntegrations,
  17. GatewayIntentBits.GuildInvites,
  18. GatewayIntentBits.GuildMembers,
  19. GatewayIntentBits.GuildMessageReactions,
  20. GatewayIntentBits.GuildMessageTyping,
  21. GatewayIntentBits.GuildMessages,
  22. GatewayIntentBits.GuildPresences,
  23. GatewayIntentBits.GuildScheduledEvents,
  24. GatewayIntentBits.GuildVoiceStates,
  25. GatewayIntentBits.GuildWebhooks
  26. ],
  27. partials: [Partials.Channel, Partials.Message, Partials.User, Partials.GuildMember, Partials.Reaction]
  28. });
  29.  
  30. const configuration = new Configuration({
  31. apiKey: process.env.CHATGPTKEY
  32. });
  33.  
  34. const openai = new OpenAIApi(configuration);
  35.  
  36.  
  37. module.exports = {
  38. name: 'ask-gpt',
  39. description: "Ask ChatGPT (3.0) a question!",
  40. type: ApplicationCommandType.ChatInput,
  41. cooldown: 3000,
  42. options: [
  43. {
  44. name: 'prompt',
  45. description: 'The question you would like to ask.',
  46. type: ApplicationCommandOptionType.String,
  47. required: true
  48. }
  49. ],
  50. run: async (client, interaction) => {
  51. const user = interaction.user;
  52. const question = interaction.options.getString('prompt')
  53.  
  54. await interaction.deferReply();
  55.  
  56.  
  57. try {
  58. const res = await openai.createCompletion({
  59. model: 'text-davinci-003',
  60. maxtokens: 2046,
  61. temperature: 0.5,
  62. prompt: question
  63. })
  64.  
  65. const embed = new EmbedBuilder()
  66. .setDescription(`\`\`\`${res.data.choices[0].text}\`\`\``)
  67.  
  68.  
  69. await interaction.editReply({embeds: [embed] });
  70.  
  71. } catch (e) {
  72. return await interaction.editReply({content: `Request failed with status code **${e.response.status}**`, ephemeral: true })
  73. }
  74.  
  75.  
  76.  
  77.  
  78. }
  79. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement