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.3.tar.gz (5.1 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: discord_game-0.1.3.tar.gz
  • Upload date:
  • Size: 5.1 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.3.tar.gz
Algorithm Hash digest
SHA256 9cf49fb5f65769b115dc7bbfda83ba824eb70a2a6138a3ca040243068161657e
MD5 21f3046d3bf647906266e6f24211a219
BLAKE2b-256 8194e2753e5e63fb97d6d515d0d32c01da0772112e6c2e1316f7d05f76c0b1c6

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