I'm trying to make a Discord bot with Discordpy and WikipediaApi. The bot is supposed to print Wikipedia summary after entering an appropriate sentence: "What is...?" or "Who is...?". So far, it's working well, but the Wikipedia page is defined in the code. I want take a page title as keyword from user, for example, he might ask "What is Microsoft?" or "Who is Elon Musk?" and receive a reply (if a page exists in Wikipedia, of course). I know I should use client.wait_for(), but I feel confused with that, as the input will be a part of longer sentence.
import discord
import wikipediaapi
@client.event
async def on_message(message):
if not (message.author == client.user):
if (message.mention_everyone == False):
if (client.user.mentioned_in(message) or isinstance(message.channel, discord.abc.PrivateChannel)):
async with message.channel.typing():
if message.content.startswith('What is') or message.content.startswith('Who is'):
wiki_wiki = wikipediaapi.Wikipedia('pl')
page_py = wiki_wiki.page('Elon Musk') <----- HERE
await message.channel.send("Page - Summary: %s" % page_py.summary)
client.run('token')
requestsapi to get the source code of the page, if it exists