Jere's Techblog

Create Discord Bot

I way toying arround with Discord and Python because I wanted to record the messages and reactions of users.
Therefore I wrote a bot with the library discord.py My first attempts with Python…or let’s say a try and error session….

But in the end I was able toget the reactions and log messages.

below some good references and instructions and an example of my discord bot

Prerequisits:

Installation of Python 3.5<

Python Discord API – https://github.com/Rapptz/discord.py

py -3 -m pip install -U discord.py

Python await – https://pypi.org/project/await/

pip install await

Python async – https://pypi.org/project/async/

pip install async

References:

Documentation

https://discordapp.com/developers/docs/intro

https://discordpy.readthedocs.io/en/latest/discord.html

https://discordpy.readthedocs.io/

Tutorial

https://realpython.com/how-to-make-a-discord-bot-python/

My own Bot

import discord
from discord.ext import commands

client = commands.Bot(command_prefix='.')

@client.event
async def on_ready():
   #a = discord.utils.get(client.get_all_members(),name="Test-User", discriminator="9635").id  #GetUserID
    print('Bot is ready.')


"""  crawl message
@client.event
async def on_message(message):
    if str(message.author) == 'Test-user#111':
         print(f'{message.content} RECEIVED!.')
    else:
        print(f'{message.content} wrong User!.')
"""

#get reaction an log it on another channel crawl message with some condition as an example
@client.event
async def on_reaction_add(reaction, user):
    channel = client.get_channel(6637461198)
    print(f'{reaction}')
    if str(reaction.message.author.id) == '579155970803':
        if str(user.id) != '57915597803':
            await channel.send('[{0.display_name}] -  {0} has reacted with {1.emoji}!; ID = {1.message.id} '.format(user, reaction))
client.run(' some API-DiscordServer String here ')
Continue reading...

vertical Cursor selection

Perhaps you remember the moment when you found out that you can replace the text at the cursor position with the “Insert” key and that it will no longer insert the text but overwrite it at this position.
This was a WOW-effect for me “finally I know how to switch off this stupid function”. With regard to users who work exclusively or very much with the keyboard; as in the old DOS times or today on Linux (with editors like vim /nano) this makes sense.
I’m always amazed that there are users who don’t know this. If they accidentally press the key, they restart the PC to fix this “error”.

But there is one more thing that only a few people know.
After all, the nice thing about IT is that you never stop learning and you learn every day something new.

About 5 years ago I asked myself how I could remove the first character on every line from a list.
The list had about 4000 characters…so a manual intervention was out of the question.
I thought: “There are some ways to do this, e.g. with a simple loop script or by concatenating characters/words in Excel”.
But to be honest my script/programming knowledge was virtually non-existent at that time and I didn’t have time for the Excel crafting either…it had to be an easy way, because it was an important file that had to be edited fast.

Then I asked myself if you could simply mark “vertically” with the mouse cursor and delete the corresponding character.

Google gave me the answer!
Since then I use this method very often to edit files.

And now for the trick:
SHIFT + ALT” with the arrow keys “UP/Down” serve as navigation for the vertical marking.

Unfortunately not all programs/editors support this (e.g. the normal Windows Notepad program can’t do this).

I have successfully tested this function with the following programs:

 

  • Atom Editor
  • Notepad++
  • Powershell_ISE
  • Atom Editor
  • Visual Studio
  • Visual Studio Code (depending on the user/profile setting).

It is also possible to mark whole blocks by using the arrow keys “SHIFT + ALT” & “UP/Down + Left/Right”.

Example “Block Selection” in Notepad++:

Continue reading...