discord rebot
1.0.0
UnsordRebot是帶有授權的基於正則命令的命令映射Discord Bot框架。
使用discord.py的discordrebot易於使用,最小和異步框架
大多數機器人都使用單個前綴,字符串來匹配命令,而args則由空格分配,例如!cmd arg1 arg2 。
但是,DiscordRebot使用Regex匹配命令並捕獲參數。它對匹配命令和解析參數提供了更大的控制權。
此外,它也提供了在執行命令之前授權該消息的作者的授權。
帶有迴聲命令的最小機器人
from discordRebot import *
client = discord . Client ()
key = Mapper ()
@ key ( re . compile ( r"^!echo (.*)$" )) # Eg: '!echo hello' -> 'hello'
def echo ( msg , string ):
return string
echo . auth = None
client . event ( Manager ( key ). on_message )
import os ; client . run ( os . environ [ "DBToken" ])您可以在示例目錄中找到更多示例。
它也支持
@ key ( re . compile ( r"^!ticker (d*) (d*)$" ))
async def ticker ( msg , delay , to ):
delay , to = int ( delay ), int ( to )
for i in range ( to ):
yield i
await asyncio . sleep ( delay )授權消息作者
基於
1234567890'user#1234' @ key ( "am i authorized ?" )
def amiauthorized ( msg ):
return "Authorized"
amiauthorized . auth = { 1234567890 , 'user#1234' }
# only executable by user1 (with id 1234567890) and user2 (with username 'user#1234')可以將多個命令與消息匹配
@ key ( re . compile ( r"^([sS]*)$" ))
def printmsg ( msg , content ):
print ( f"@ { msg . author } :" )
print ( content )
@ key ( "whereami" )
def whereami ( msg ):
if msg . guild :
return msg . guild . name
else :
return "DM"
DISCORD-REARGPARSE(用於命令中的基於REGEX的Fulled Discord Bot)