昨天写完查询物品拍卖价格网址後发现...既然都有各国物品名称了
乾脆多做一个查询各国物品名称并附上WIKI连结的功能
那麽就直接附上程序码~
import discord
import requests
import pandas as pd
import pickle
import difflib
from dotenv import load_dotenv
if __name__ == '__main__':
#读取Token
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
intents = discord.Intents.default()
intents.members = True
client = discord.Client(intents=intents)
embed = discord.Embed()
@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)
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)
await message.reply(embed=embed, mention_author=True)
# await message.channel.send(embed=embed)
#查市价
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']})"
await message.reply(embed=embed, mention_author=True)
else:
embed.description = f"[{user_word}价格网址](https://universalis.app/market/{user_word})"
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)
await message.reply(embed=embed, mention_author=True)
else:
await message.reply("无相关资讯")
client.run(TOKEN) #TOKEN 在刚刚 Discord Developer 那边「BOT」页面里面
呈现结果如下
>>: 当你发现自己和大众站在一边的时候,反而该停下来反思一下。
以下笔记摘录自『 The Go Workshop 』。 Go语言只支援一种回圈回圈叙述,就是for回...
上篇我们讲到在AWS Console 里面如何建立role以及Policy,今天我们来看如何启用MF...
终於到了第30天了,这30天说长不长,说短不短中间有一度想要放弃但最後还是撑过来了??,还蛮开心自己...
这篇会介绍图表套件Charts的功能 graphView.leftAxis.enabled = fa...
React的核心就是将UI拆成不同的程序码,以元件的方式独立,让元件可以在主程序中重复利用。 而要使...