Skip to main content

Create a discord game

Project description

discord.py-game-engine

A game engine for discord


How to use

If you want to see some examples go here or follow almong this tutorial to get a basic understanding of how this module works.

Start by importing the module

import discord_game
from discord_game import screen

You will also need the discord libary to create the client

import discord

Then you can start by creating the discord client

client = discord.Client()

Now you can create the game and set its startcommand. Our is !start

game = discord_game.Game(client, "!start")

Use the onStart event to run code when someone starts the game. The onBotReady runs when the bot/client is ready.

@game.event.onStart
async def onStart(display):
    print("The game is started")

@game.event.onBotReady
async def ready():
    print("bot is ready")

Don't forget to add client.run(token) at the end of the file

client.run("Your token")

You can create a sprite like this

mySprite = screen.Sprite(display, ["costume", "with", "multiple rows"], 0, 0) # and lastly x and y pos

Then you will need to update the display

await display.update()

To create a button you do it like this

myButton = await s.addButton("Click me!")

To get a button click put this code inside the onstart function

@myButton.onClick
async def clicked(btn):
    print("You clicked me!")

The complete code

import discord_game
from discord_game import screen
import discord

client = discord.Client()

game = discord_game.Game(client, "!start")

@game.event.onStart
async def onStart(display):
    print("The game is started")

@game.event.onBotReady
async def ready():
    print("bot is ready")

    mySprite = screen.Sprite(display, ["costume", "with", "multiple rows"], 0, 0) # and lastly x and y pos

    await display.update()

    myButton = await s.addButton("Click me!")

    @myButton.onClick
    async def clicked(btn):
        print("You clicked me!")
    
client.run("Your token")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discord_game-0.1.2.tar.gz (4.8 kB view details)

Uploaded Source

File details

Details for the file discord_game-0.1.2.tar.gz.

File metadata

  • Download URL: discord_game-0.1.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.1

File hashes

Hashes for discord_game-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3967d32752c8fa925d0c61762d4fee43b6d4fef737b9e8f9e9cc8c4347fb9a75
MD5 43acf36df21026e2f243dcc7eaa84013
BLAKE2b-256 f3b2d49bb57e1840a689eaacf75eb987a59f8ed7dc29e48684a5ab8a76c6c5ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page