Comment in a post using beem | Steem Discord Bot Python #12

in Steem Dev11 months ago

Welcome back, developers.

Greetings to all Steem enthusiasts! In today's lecture, we will learn how to install the beem library for interacting with the Steem blockchain, as well as how to cast a vote on a post.

updates.png

Summary

We established the necessary environment for developing a Python-based Discord bot during our first lecture. In our second lecture we create a discord bot token, configure the bot and generate the invite link. We used the invite link and added the bot to our server. In our third lecture, we will bring the Community-Bot online in our local environment.

In the 4th lecture, we successfully developed our initial bot command, !info. We also learned how to create functions and retrieve data using the requests library in 5th lecture. We implemented the !info command in 6th lecture which is used fetch the information of any steem user.

In the 7th lecture, we learned how to send an embedded message with columns, images, and a profile image. In lecture 8th we learn how to generate a report for the community. In lecture 9th we learned how to develop a report and create a text file, then attach it to a Discord bot. In 10th lecture we learned how to get a single-author report for a community. In today's lecture, In 11th lecture learned how to install the beem library to interact with the Steem blockchain and how to case vote to a post.

In today's lecture, we will learn how to use the Beem Python library to send comments on a post. Let's begin.

Procedure
  • We need the private posting key and the account name for this purpose. The Steem instance is already created in lecture 11 in the utils file. We will use this instance to send a comment on a post. Let's create a new comment !send, we will use this command to send a comment on a given post link.

image.png

  • Now, configure the command in the main.py file. We will accept two parameters in this command: the first one being the command itself, and the second one being the post link for which we will send comments.

image.png

  • We will use the Comment method provided by the beem API. First, we create the comment instance with the identifier and the blockchain instances.
from beem.comment import Comment
# !send command
        if command == utils.commands[3]:
            if len(props) == 2:
                post_link = str(props[1]).split('/')
                post_link.reverse()
                perm_link = post_link[0]
                post_author = post_link[1]
                identifier = f'{post_author}/{perm_link}'
                body = 'Hello testing the steem community bot created by @faisalamin'
                await message.channel.typing()
                try:
                    steem = utils.steem_vote_instance
                    comment = Comment(authorperm=identifier, blockchain_instance=steem)
                    response = comment.reply(body=body, author=utils.voter_username)
                    if response.get('trx_id'):
                        await message.reply(f'Comment sent to www.steemit.com/@{identifier}')
                    else:
                        await message.reply(f'Failed')

                except Exception as e:
                    await message.channel.send("Error: " + str(e))

image.png

  • Make sure to add the private key for the account to be used for comments. Run the main.py file and use the command !send. Here is the final result.

image.png

Github
Steem Discord Bot Series
SteemPro Official

Cc: @blacks
Cc: @rme
Cc: @hungry-griffin
Cc: @steemchiller
Cc: @steemcurator01
Cc: @pennsif
Cc: @future.witness
Cc: @stephenkendal
Cc: @justyy


Best Regards @faisalamin

Download SteemPro Mobile

Sort:  

Upvoted! Thank you for supporting witness @jswit.

Coin Marketplace

STEEM 0.17
TRX 0.15
JST 0.028
BTC 59774.28
ETH 2422.19
USDT 1.00
SBD 2.44