一个Python Discord库,用于在Discord服务器中开发游戏。
DiscordGame的Python项目详细描述
不和谐游戏
DiscordGame是一个制作游戏的Python框架 从简单的小游戏如井字游戏 以成熟的地牢和龙族内部的争斗。
入门
安装
$ pip install discordgame
或者克隆回购
^{pr2}$然后跑
$ python setup.py install
用法
不和谐游戏的结构是这样的。 当游戏处于活动状态时,每当一个触发事件如反应(称为按钮)或新消息被发送时, 这些事件将传递给注册到GameHost对象的所有游戏。 正如您在这里看到的on_text_事件和on__button_事件。。。在
importdiscordgameasdg
Here's a couple of examples to help you get the gist of how this framework works...
- 一个简单的MadLib,由
discordgame
:
importdiscordimportdiscordgameasdgclassMadLib(dg.Game):game_name='MadLib'def__init__(self,ctx):# Creates a list of blanksself.word_blanks=['(blank)']*8# Assign a MadLib string to a variable.self.lib='The {}{}ed across the {} to get to the {}{}. It wanted to get to the {} so it could {} with a {}.'# Initialize the Parent Game class with the MadLib specific values.super().__init__(self.game_name,[[self.lib.format(*self.word_blanks)]],ctx=ctx,needs_text_input=True)# Define events to be triggered on a user's message event.asyncdefon_text_event(self,player:discord.User,text:str):try:next_index=self.word_blanks.index('(blank)')# Finds the left-most blank in the list.self.word_blanks.pop(next_index)# Pops that blank from the list.self.word_blanks.insert(next_index,text)# Inserts the user's word into the said blank.self.stats['Blanks to Fill ->']=len([wordforwordinself.word_blanksifword=='(blank)'])# ^^ Updates the Blanks to fill Counter.awaitself.update_layout([[self.lib.format(*self.word_blanks)]])# Sends the changes to discord.if'(blank)'notinself.word_blanks:self.stop()awaitplayer.send(self.lib.format(*self.word_blanks))# Sends the final MadLib to the channel.exceptValueError:# If there's no blank in the list.self.stop()awaitplayer.send(self.lib.format(*self.word_blanks))# Sends the final MadLib to the channel.
- 一个用
discordgame
:
更多功能
测试和问题
我们欢迎任何关于这个框架的新见解和新问题。 要发布问题,请转到我们存储库中的问题页面->;https://github.com/GrandMoff100/DiscordGame并打开一个新问题。 我们期待着修复我们可能遗漏的任何错误或问题。在
贡献
我们希望你能为我们做出贡献!欢迎新功能和优化! 只需分叉存储库并进行更改,然后使用您的改进提出请求。 如果你做了足够的改进,我们会一直把你作为贡献者。在
- 项目
标签: