[PYTHON] The story of making a question box bot with discord.py

Introduction

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.

Advance preparation

--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

How to use

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 &

Image story


@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.

in conclusion

I am trying to spit out logs to store.csv. Please comment out if you don't need it

Operation example 20200510_002453.jpg

Recommended Posts

The story of making a question box bot with discord.py
The story of making a university 100 yen breakfast LINE bot with Python
The story of making a standard driver for db with python.
The story of making a module that skips mail with python
The story of making a lie news generator
The story of making a mel icon generator
The story of making a sound camera with Touch Designer and ReSpeaker
The story of making a box that interconnects Pepper's AL Memory and MQTT
The story of making a web application that records extensive reading with Django
The story of implementing the popular Facebook Messenger Bot with python
The story of writing a program
A story stuck with the installation of the machine learning library JAX
Tweet the weather forecast with a bot
Knowledge when making a bot using discord.py
The story of making Python an exe
The story of making an immutable mold
The story of blackjack A processing (python)
The story of creating a bot that displays active members in a specific channel of slack with python
A story that visualizes the present of Qiita with Qiita API + Elasticsearch + Kibana
The story of a Parking Sensor in 10 minutes with GrovePi + Starter Kit
The story of having a hard time introducing OpenCV with M1 MAC
The story of making a package that speeds up the operation of Juman (Juman ++) & KNP
Tweet the weather forecast with a bot Part 2
The story of making the Mel Icon Generator version2
The story of making a tool to load an image with Python ⇒ save it as another name
The story of making soracom_exporter (I tried to monitor SORACOM Air with Prometheus)
The story of sys.path.append ()
A story that reduces the effort of operation / maintenance
A story about making 3D space recognition with Python
The story of stopping the production service with the hostname command
The story of replacing Nvidia GTX 1650 with Linux Mint 20.1.
The story of sharing the pyenv environment with multiple users
Make a BOT that shortens the URL of Discord
Take a screenshot of the LCD with Python-LEGO Mindstorms
A story that struggled with the common set HTTP_PROXY = ~
A story about making Hanon-like sheet music with Python
Visualize the characteristic vocabulary of a document with D3.js
A story about changing the master name of BlueZ
Zip 4 Gbyte problem is a story of the past
Calculate the product of matrices with a character expression?
The story of creating a VIP channel for in-house chatwork
The story of building Zabbix 4.4
Create a bot that only returns the result of morphological analysis with MeCab on Discord
A network diagram was created with the data of COVID-19.
Measure the importance of features with a random forest tool
[Apache] The story of prefork
Get the id of a GPU with low memory usage
Get UNIXTIME at the beginning of today with a command
Let's execute the command on time with the bot of discord
The story of a Django model field disappearing from a class
A story about an amateur making a breakout with python (kivy) ②
The story of displaying images with OpenCV or PIL (only)
Create a Twitter BOT with the GoogleAppEngine SDK for Python
The story of rubyist struggling with python :: Dict data with pycall
A story about how to deal with the CORS problem
A story about an amateur making a breakout with python (kivy) ①
A story about making a tanka by chance with Sudachi Py
[Python] The first step to making a game with Pyxel
Analyze the topic model of becoming a novelist with GensimPy3
The story of creating a database using the Google Analytics API
A story about predicting prefectures from the names of cities, wards, towns and villages with Jubatus