Skip to content

Instantly share code, notes, and snippets.

@OfficialGodbless
Created April 20, 2025 18:58
Show Gist options
  • Select an option

  • Save OfficialGodbless/ec8c2d5ed8739b1bc3fb6ffb71af88fa to your computer and use it in GitHub Desktop.

Select an option

Save OfficialGodbless/ec8c2d5ed8739b1bc3fb6ffb71af88fa to your computer and use it in GitHub Desktop.
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