Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ire4ever1190/dimscmd
A command handler for dimscord
https://github.com/ire4ever1190/dimscmd
discord hacktoberfest library nim
Last synced: 11 days ago
JSON representation
A command handler for dimscord
- Host: GitHub
- URL: https://github.com/ire4ever1190/dimscmd
- Owner: ire4ever1190
- License: mit
- Created: 2020-12-18T03:49:20.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-08-16T06:43:30.000Z (3 months ago)
- Last Synced: 2024-08-17T00:25:51.880Z (3 months ago)
- Topics: discord, hacktoberfest, library, nim
- Language: Nim
- Homepage:
- Size: 354 KB
- Stars: 29
- Watchers: 4
- Forks: 6
- Open Issues: 6
-
Metadata Files:
- Readme: readme.rst
- License: LICENSE
Awesome Lists containing this project
README
***********************
Dimscord Command Handler
***********************.. image:: https://github.com/ire4ever1190/dimscmd/workflows/Tests/badge.svg
:alt: Test statusThis is built on top of the amazing `dimscord library `_ so if you have any questions about using dimscord or dimscmd then join the `dimscord discord `_ (please send questions about dimscmd in the #dimscmd channel)
`Docs available here `_
Install
====.. code-block::
nimble install dimscmd
Setup
=====First create the handler object
.. code-block:: nim
import dimscord
import dimscmd
let discord = newDiscordClient(token)
var cmd = discord.newHandler() # Must be varThen add the handler into your message_create event using `handleMessage()` proc. It is in this proc
that you can define the prefix (or prefixes) that you want the bot to handle.. code-block:: nim
proc messageCreate (s: Shard, msg: Message) {.event(discord).} =
discard await cmd.handleMessage("$$", s, msg) # Returns true if a command was handled
# You can also pass in a list of prefixes
# discard await cmd.handleMessage(@["$$", "&"], s, msg)Use
====Commands are created using Nim's do notation
.. code-block:: nim
cmd.addChat("ping") do ():
discard await discord.api.sendMessage(msg.channelID, "pong") # Message is passed to the proc as msg# If msg is not to your fancy then you can change it
cmd.addChat("ping") do (m: Message):
discard await discord.api.sendMessage(m.channelID, "pong")But you are probably wondering "can I add parameters to my commands?" and the answer is yes and it is very easy.
Just add parameters to the signature and you're off.. code-block:: nim
cmd.addChat("echo") do (word: string):
discard await discord.api.sendMessage(m.channelID, word)# You can add as many types as you want
cmd.addChat("repeat") do (word: string, times: int):
for i in 0..