import asyncio
import discord
from discord.ext import commands
import urllib3
import json
from langchain.load.dump import dumps
openApiURL = "http://aiopen.etri.re.kr:8000/WiseQAnal"
accessKey = "(key)"
intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix='>', intents=intents)
token="(key)"
@client.event
async def on_ready():
print("Logged in as ")
print(client.user.name)
print(client.user.id)
print("===========")
activity = discord.Game(name="with the API")
await client.change_presence(status=discord.Status.idle, activity=activity)
@client.event
async def on_message(UserMessage):
if UserMessage.author.bot:
return None
id=UserMessage.author.id
channel=UserMessage.channel
content=UserMessage.content
requestJson = {
"argument": {
"text": content
}
}
http = urllib3.PoolManager()
response = http.request(
"POST",
openApiURL,
headers={"Content-Type": "application/json; charset=UTF-8", "Authorization": accessKey},
body=json.dumps(requestJson)
)
Result=json.loads(str(response.data,"utf-8"))
await channel.send(json.dumps(Result))
client.run(token)
I want to print content in my discord channel. How can I extract that content form the json on bottom? my discord token and api key was deleted for security
{"result":0,"return_object":{"orgQInfo":{"orgQUnit":{"strQuestion":"안녕?","strTaggedQ":"안녕/IC+?/SF","ndoc":{"doc_id":"","DCT":"","category":"","category_weight":0,"title":{"text":"","NE":""},"metaInfo":{},"sentence":[{"id":0,"reserve_str":"","text":"안녕?","morp":[{"id":0,"lemma":"안녕","type":"IC","position":0,"weight":0.00241277},{"id":1,"lemma":"?","type":"SF","position":6,"weight":1}],"morp_eval":[{"id":0,"result":"안녕/IC+?/SF","target":"안녕?","word_id":0,"m_begin":0,"m_end":1}],"WSD":[{"id":0,"text":"안녕","type":"IC","scode":"00","weight":0,"position":0,"begin":0,"end":0},{"id":1,"text":"?","type":"SF","scode":"00","weight":1,"position":6,"begin":1,"end":1}],"word":[{"id":0,"text":"안녕?","type":"","begin":0,"end":1}],"NE":[],"chunk":[{"id":0,"text":"안녕?","type":"IP","begin":0,"end":1,"weight":1}],"dependency":[{"id":0,"text":"안녕?","head":-1,"label":"IP","mod":[],"weight":0.777831}],"phrase_dependency":[{"id":0,"label":"IP","text":"안녕?","begin":0,"end":0,"key_begin":0,"head_phrase":-1,"sub_phrase":[],"weight":0,"element":[]}],"SRL":[],"relation":[],"SA":[],"ZA":[]}],"entity":[]},"vQTs":[{"qt":11,"strQTClue":""}],"vQFs":[],"vLATs":[],"vSATs":[{"strSAT":"DS_DEFINITION","expanse_SAT":[],"dConfidenceSAT":0.7681},{"strSAT":"PS_NAME","expanse_SAT":[],"dConfidenceSAT":0.154066},{"strSAT":"QT_PRICE","expanse_SAT":[],"dConfidenceSAT":0.212015}],"vSATRoots":[{"strSAT":"DS_DEFINITION","expanse_SAT":[],"dConfidenceSAT":0.577773},{"strSAT":"QT_OTHERS","expanse_SAT":[],"dConfidenceSAT":0.534239},{"strSAT":"PS_OTHERS","expanse_SAT":[],"dConfidenceSAT":0.522282},{"strSAT":"LC_OTHERS","expanse_SAT":[],"dConfidenceSAT":0.520149},{"strSAT":"DT_OTHERS","expanse_SAT":[],"dConfidenceSAT":0.517169},{"strSAT":"CV_OTHERS","expanse_SAT":[],"dConfidenceSAT":0.508471}],"vTitles":[],"vQTopic":[],"answerConstraint":[],"dIntegrativeConf":0.811857}},"QClassification":{"ansQType":{"strQType4Chg":"서술형","dWeightCQT":1},"vSemQType":[{"strQType4Chg":"사실관계형-속성값요청형","dWeightCQT":0.907438}]}}}
I only know from googling python data to json method, not json content to python data
programmer newest is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1