今天分享如何把图片放进先前的翻译及拍卖查询功能
在universalis上每个物品都会有张图片
点击F12检查图片连结後发现他跟物品网址一样是用ID来辨识
接下来新增下列程序码
embed.set_thumbnail(url=<图片连结>)
附上完整程序码
import discord
import requests
import pandas as pd
import pickle
import difflib
from discord.ext import commands
import ahocorasick
from bs4 import BeautifulSoup
from dotenv import load_dotenv
import os
import chardet
if __name__ == '__main__':
#读取Token
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
#读取字典
with open("item_dict.pkl", "rb") as tf:
item_dict = pickle.load(tf)
wordlist = [word for word in item_dict]
#client = discord.Client()
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
# client = commands.Bot(command_prefix='.',intents =intents)
embed = discord.Embed()
# bot = discord.ext.commands.Bot(command_prefix = "your_prefix")
@client.event
#当有讯息时
async def on_message(message):
#排除自己的讯息,避免陷入无限循环
if message.author == client.user:
return
#翻译
if message.content.startswith('?tr '):
user_word = message.content.replace('?tr ',"")
user_word = user_word.lstrip().rstrip()
if user_word in item_dict:
if "简体中文" in item_dict[user_word]:
user_wordlist = [f"{key} : {value}" for key,value in item_dict[user_word].items()]+[f"[详细资讯连结](https://ff14.huijiwiki.com/wiki/%E7%89%A9%E5%93%81:{item_dict[user_word]['简体中文']})"]
embed.description = "\n".join(user_wordlist)
embed.set_thumbnail(url = f"https://universalis-ffxiv.github.io/universalis-assets/icon2x/{item_dict[user_word]['ID']}.png")
await message.reply(embed=embed, mention_author=True)
# await message.channel.send(embed=embed)
else:
user_wordlist = [f"{key} : {value}" for key,value in item_dict[user_word].items()]+[f"[详细资讯连结](https://ff14.huijiwiki.com/wiki/%E7%89%A9%E5%93%81:{user_word})"]
embed.description = "\n".join(user_wordlist)
embed.set_thumbnail(url = f"https://universalis-ffxiv.github.io/universalis-assets/icon2x/{item_dict[user_word]['ID']}.png")
await message.reply(embed=embed, mention_author=True)
# await message.channel.send(embed=embed)
else:
wordsim_list = difflib.get_close_matches(user_word,wordlist,10,cutoff=0.1)
if len(wordsim_list) > 0:
embed.description ="你可能要查询的词:\n"+"\n".join(wordsim_list)
await message.channel.send(embed=embed)
else:
await message.channel.send("无相关资讯")
#查市价
elif message.content.startswith('?bs '):
user_word = message.content.replace('?bs ',"")
user_word = user_word.lstrip().rstrip()
if user_word in item_dict:
if "ID" in item_dict[user_word]:
embed.description = f"[{user_word}价格网址](https://universalis.app/market/{item_dict[user_word]['ID']})"
embed.set_thumbnail(url = f"https://universalis-ffxiv.github.io/universalis-assets/icon2x/{item_dict[user_word]['ID']}.png")
await message.reply(embed=embed, mention_author=True)
else:
embed.description = f"[{user_word}价格网址](https://universalis.app/market/{user_word})"
embed.set_thumbnail(url = f"https://universalis-ffxiv.github.io/universalis-assets/icon2x/{item_dict[user_word]['ID']}.png")
await message.reply(embed=embed, mention_author=True)
else:
wordsim_list = difflib.get_close_matches(user_word,wordlist,10,cutoff=0.1)
if len(wordsim_list) > 0:
embed.description ="你可能要查询的词:\n"+"\n".join(wordsim_list)
embed.set_thumbnail(url = f"https://universalis-ffxiv.github.io/universalis-assets/icon2x/{item_dict[user_word]['ID']}.png")
await message.reply(embed=embed, mention_author=True)
else:
await message.reply("无相关资讯")
elif message.content.startswith('请问'):
user_word = message.content.replace('请问',"")
actree = build_actree(wordlist=basequestion_list)
send_list = [i[1][1] for i in actree.iter(user_word)]
if len(send_list) == 1:
wiki_url = f"https://ff14.huijiwiki.com/wiki/{base_knowledge[send_list[0]]}"
await message.reply(f"这篇可以参考看看~\n{wiki_url}", mention_author=True)
呈现画面:
<<: [Day 09] tinyML开胃菜Arduino IDE上桌(下)
巢状回圈 所谓的巢状回圈,就是一个回圈里还有另一个回圈,两者变数尽量不要相同以免搞混 Break指...
今天来创作原创图,其实这两天发文这麽敷衍就是在画这个哈哈哈,然而时间还是不够,没时间画得太细,也没时...
接下来要讲有关线上取图的banner,会分开主要是因为有些微的不一样,包含在Manifest中添加网...
前言 前面介绍的工具都是命令行工具,但存在着一些的不便 分析数据透过终端机文字的方式显示,不够直觉 ...
Sort Key的用途 在建立Table的时候, 可看到有一个非必要的选项Sort Key. 在某些...