Okay so I know that there is a way to open let's say a wiki. By typing a command(archive) it will then search the wiki and return with a message containing certain information about what you searched for.
I know that you can use webhooks for this, but I don't know how. Can anyone of you help?
There are multiple ways to get a summary of a page from a wiki. The easiest of them is probably the TextExtracts extension that allows you to get the plain text of some article. However, this only works if the wiki in question has that extension installed -- the Star Wars Fandom wiki that you wanted to work with does not. Nevertheless, this should give you an idea of how to use the MediaWiki API to get information about articles from there.
import discord
from discord.ext import commands
import aiohttp
bot = commands.Bot(command_prefix='-')
WIKI_ENDPOINT = 'https://en.wikipedia.org/w/api.php'
NUMBER_OF_SENTENCES = 3 # (must be between 1 and 10)
@bot.command('lookup')
async def lookup_wiki(ctx, *query_elements):
query = ' '.join(query_elements)
params = {
"action": "query",
"prop": "extracts",
"titles": query,
"exsentences": NUMBER_OF_SENTENCES,
"explaintext": "true",
"format": "json",
"redirects": "true"
}
headers = {"User-Agent": "BOT-NAME_CHANGE-ME/1.0"}
async with aiohttp.ClientSession() as session:
async with session.get(WIKI_ENDPOINT, params=params, headers=headers) as r:
data = await r.json()
pages = data['query']['pages']
page = pages[ list(pages)[0] ]
try:
extract = page['extract']
if extract is None: raise ValueError
except:
extract = f"We could not fetch an extract for this page. Perhaps it does not exist, or the wiki queried does not support the **TextExtracts** MediaWiki extension: https://www.mediawiki.org/wiki/Extension:TextExtracts\nThe page data received is: `{page}`"
await ctx.send(extract)
bot.run('your bot token here')