-
-
Save OfficialGodbless/ec8c2d5ed8739b1bc3fb6ffb71af88fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const { bot } = require("../lib/"); | |
| const axios = require("axios"); | |
| bot( | |
| { | |
| pattern: "wiki ?(.*)", | |
| desc: "Search Wikipedia for a topic", | |
| type: "info", | |
| }, | |
| async (message, match) => { | |
| try { | |
| if (!match) return await message.send("Please provide a search query\nExample: .wiki Albert Einstein"); | |
| const response = await axios.get( | |
| `https://en.wikipedia.org/api/rest_v1/page/summary/${encodeURIComponent(match)}` | |
| ); | |
| const data = response.data; | |
| const summary = data.extract || "No summary available."; | |
| const title = data.title; | |
| const wikiMessage = ` | |
| ๐ Title: ${title} | |
| ๐ Summary: ${summary} | |
| ๐ Read More: ${data.content_urls.desktop.page} | |
| `; | |
| await message.send(wikiMessage); | |
| } catch (error) { | |
| console.error("Wiki Error:", error); | |
| let errorMsg = "โ ๏ธ Failed to fetch Wikipedia information"; | |
| if (error.response?.status === 404) { | |
| errorMsg = "โ ๏ธ Article not found. Try another query."; | |
| } | |
| await message.send(errorMsg); | |
| } | |
| } | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment