I made a question box bot on Discord. The technical story is to get the link of the image and transfer it. The repository is here
As a motive for making
--Ensure psychological safety for questions --Increase opportunities for information sharing by disclosing questions --Increase the number of people who can answer by making the question public
And so on. I hope it will be an opportunity to improve the DM conversation problem.
--Create a VM instance --Create an environment for Python3 --Pass through Git's path
I think these articles will come out, so please google for a good feeling. If you are not sure, please ask a question
Replace python
with python3
depending on your environment.
$ git clone https://github.com/t4t5u0/question_box.git
$ cd question_bot
$ vim info.json
$ nohup python main.py &
@client.event
async def on_message(message):
for file_ in message.attachments:
file_url = file_.url
file_name = file_.filename
async with aiohttp.ClientSession() as session:
async with session.get(file_url) as resp:
if resp.status != 200:
return await to_send_channel.send('Could not get the file')
data = io.BytesIO(await resp.read())
#Send part
await to_send_channel.send(file=discord.File(data, file_name))
message.attachment
contains a list of attached file-like object information.
The url of the image is stored in message.attachment.url
.
Implemented based on Official sample.
I am trying to spit out logs to store.csv. Please comment out if you don't need it
Operation example
Recommended Posts