toowake

wiki.js

Aug 7th, 2023
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. const wiki = require("wikijs");
  2. const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
  3.  
  4. module.exports = {
  5. data: new SlashCommandBuilder()
  6. .setName('wiki')
  7. .setDescription('search something on wikipedia')
  8. .addStringOption(option => option.setName('search').setDescription('the thing you want to search on wiki').setRequired(true)),
  9. async execute (interaction) {
  10.  
  11. const query = interaction.options.getString('search')
  12.  
  13. await interaction.deferReply();
  14.  
  15. const search = await wiki.search(query);
  16. if (!search.results.length) return await interaction.editReply({ content: `Wikipedia doesn't seem to know what your searching for....`, ephemeral: true});
  17.  
  18. const result = await wiki.page(search.results[0]);
  19.  
  20. const summary = await result.summary();
  21. if (summary.length > 8192) return await interaction.reply({ content: `${summary.slice(0, 2048)}`, ephemeral: true});
  22. else {
  23. const embed = new EmbedBuilder()
  24. .setColor('Blue')
  25. .setTitle(`Wiki Search: ${result.raw.title}`)
  26. .setDescription(`\`\`\`${summary.slice(0, 2048)}\`\`\``)
  27.  
  28. await interaction.editReply({ embeds: [embed] });
  29. }
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment