Package: discord-notifier-bot
A simple pythonDiscordbot to send messages to Discord channel via command line.It allows markdown formatted messages and attaching files.It registers the following commands:dbot-run- main CLI entry-pointdbot-message- (short-hand) to send a message, or even pipe-message contentsdbot-file- (short-hand) to send a file with an messageRequirementsPython >= 3.6 (see badges above)
(Python 3.5.3 would technically be possible, but does not supportPEP 498 f-Strings,so a large portion of the string formatting would need rewrites.)discord.pyInstallationpython3-mpipinstalldiscord-notifier-botOptionally, install it locally with--user.ConfigurationConfiguration is done by placing a .dbot.conf file in one of the following directories:$HOME/.dbot.conf$HOME/dbot.conf./.dbot.conf./dbot.conf/etc/dbot.confAlternatively a configuration file can be provided via-c/--configCLI options.The configuration file should be a standard INI file. A template can be found in thetemplatesfolder. All configurations are placed under thediscord-botsection.Example:[discord-bot]# the bot token (used for login)token=abc# the numeric id of a channel, can be found when activating the developer options in appearanceschannel=123Usagedbot-messageanddbot-fileare simpler versions ofdbot-run.Print help and available options:dbot-run-hSending messages:# send a simple messagedbot-runmessage"Test message"# or shorter:dbot-message"Test **message**"# pipe outputecho"Test"|dbot-emessage-# wrap it inside a code-block ```
# optionally with a typecat`whichdbot-message`|dbot-message---typecat`whichdbot-message`|dbot-message---typepythonSending a file:dbot-fileREADME.rst"Your message to desribe the attached file"# or with no visible message:dbot-fileREADME.rst""# optionally also like this:dbot-runfile-fREADME.rst"Message ..."You are always able to specify the configuration file like this:dbot-run-c/path/to/dbot.conf[...]dbot-{message,file}-c/path/to/dbot.conf[...]Only withdbot-run: To display debugging information (api calls, log messages etc.):dbot-run-d[...]You may also run the bot with the python module notation. But it will only run the same entry-point likedbot-run.python-mdiscord_notifier_bot[...]Full CLI help message:usage:dbot-run[-h][--type[TYPE]][-fFILE][-cCONFIG][-d]{message,file}messagepositionalarguments:{message,file}BotactionmessageMessagetosendoptionalarguments:-h,--helpshowthishelpmessageandexit--type[TYPE]Markdowntypefortextmessages,ordefaultifasflag-fFILE,--fileFILEOptionalfiletoattachtomessage-cCONFIG,--configCONFIGConfigfile-d,--debugEnabledebugloggingusage:dbot-file[-h][-cCONFIG]filemessagepositionalarguments:filemessageoptionalarguments:-h,--helpshowthishelpmessageandexit-cCONFIG,--configCONFIGConfigfileusage:dbot-message[-h][-cCONFIG][--type[TYPE]]messagepositionalarguments:messageoptionalarguments:-h,--helpshowthishelpmessageandexit-cCONFIG,--configCONFIGConfigfile--type[TYPE]Markdowntype,ordefaultifwithoutvalueEmbedded in other scriptsSending messages is rather straightforward.
More complex examples can be found in the CLI entrypoints, see filediscord_notifier_bot.cli.
Below are some rather basic examples (extracted from the CLI code).Basic setup (logging + config loading):fromdiscord_notifier_bot.cliimportsetup_logging,load_config# logging (rather basic, if needed)setup_logging(True)# load configuration file (provide filename or None)configs=load_config(filename=None)Sending a message:fromdiscord_notifier_bot.botimportsend_message# message string with basic markdown supportmessage="The **message** to `send`"# bot token and channel_id (loaded from configs or hard-coded)bot_token,channel_id=configs["token"],configs["channel"]# send the messagesend_message(bot_token,channel_id,message)Bot Creation etc.See information provided by:Tutorial for setting up a botDiscord developer application pageShort descriptionYou have to own a Discord server! Or know someone with administrator/moderation(?) privileges.Visit and login to theDiscord developer page.Create a new application. The given name is also the visible name of the bot. (default, can be changed later?)Create a bot (on theBotpage). You should disable thePublic Botoption.The bot login token (credentials) can be found on theBotpage.Change to theOAuth2page and checkScopes:BotBot Permissions:Send Messages,Attach Files(in theText Permissionscolumn)Copy the URL in theScopessection and paste it in a new browser tab.Now you can choose one (?) of yourownDiscord servers to add the bot to.(For this you need server administration permissions, or be the owner..?)To get the channel id, send the following message on your server\#channelname, or enable developer options.
You may want to visit the following pages for more information:discord.py bot help,Discord Help,reddit post.RelatedDiscord-System-Observer-Bot,
for observing local machine status and getting messages on resource exhaustion
(former 0.2.x version code, refactored in its own package for cleaner packages)python-discord-webhook,
a python module (+ CLI) to use Discord webhooks to send messages,
(webhooks would be a more restrictive way as they are bound to a single channel
and are just a simple HTTP request, so more data friendly. You may want to check it out.)Creditseasy-telegram-cliCopyright and License InformationCopyright (c) 2020 Erik Körner.  All rights reserved.See the file “LICENSE” for information on the history of this software, terms &
conditions for usage, and a DISCLAIMER OF ALL WARRANTIES.All trademarks referenced herein are property of their respective holders.