一个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并打开一个新问题。 我们期待着修复我们可能遗漏的任何错误或问题。在

贡献

我们希望你能为我们做出贡献!欢迎新功能和优化! 只需分叉存储库并进行更改,然后使用您的改进提出请求。 如果你做了足够的改进,我们会一直把你作为贡献者。在

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Kotlin应该为Java类中的合成属性进行反射   hadoop。pig脚本与java嵌入式pig:哪一个最快?   java要求用户在不关闭程序的情况下输入一个double而不是字符串   Raspberry PI和windows pc代码之间的java差异   使用maven的基于java Spring引导概要文件的WAR   Java中的内联数组定义   jsf如何在Tomcat上安装和使用CDI?   当数据来自mySQL时,在java的微调器中删除重复项   java如何定制Android ListView的每一行?   对于web应用程序,为什么java也被称为平台无关?   java如何获得排序hashmap中两个给定键之间的所有键值?   帮我把这个Java翻译成Scheme,让我脑子里的东西运转起来   java共享子域cookie   hibernate多Java列表删除   java队列可以用来交换链表的相邻节点吗?   java遇到错误:当我在安卓应用程序中单击主屏幕快捷方式时,找不到应用程序