Python discord.py搜索并返回第一次点击的url
我想做一个机器人,这样我就可以做f.eks了。在wiki上搜索。Python discord.py搜索并返回第一次点击的url,python,python-3.x,discord.py,wikipedia,Python,Python 3.x,Discord.py,Wikipedia,我想做一个机器人,这样我就可以做f.eks了。在wiki上搜索。 命令是: !!维基(文章) 它将向您发送该网站的URL。 下面是一个我认为可能的例子 @client.command() async def wiki(ctx, search): client.search(search + "Wikipedia") await ctx.send(first_hit) 试着这样做: async def wiki(ctx, *args): term =
命令是: !!维基(文章)
它将向您发送该网站的URL。
下面是一个我认为可能的例子
@client.command()
async def wiki(ctx, search):
client.search(search + "Wikipedia")
await ctx.send(first_hit)
试着这样做:
async def wiki(ctx, *args):
term = args.replace(" ", "+")
await ctx.send("https://en.wikipedia.org/w/index.php?search=",term)
这将是搜索的链接。在本例中,它只发送搜索查询链接。使用urllib.request
(rq)模块,
然后,您可以使用rq.urlopen(link)获取此网站,解析html并选择第一个链接,然后将其发送给用户。您是尝试在discord中搜索还是在wikipedia上搜索?我希望discord机器人通过在discord中搜索将url发送到wiki文章,这样您就不会在discord中搜索