Dispy Documentation
  • Documentation
    • Getting started
      • Installation
      • Create a bot
    • Examples
  • Informations
    • Contribute
      • Adding an API function
    • Changelogs
      • 0.1.1
      • 0.1.0.7
      • 0.1.0.6
      • 0.1.0.5
      • 0.1.0
      • 0.0.1
    • Roadmap
    • Support
Powered by GitBook
On this page
  • Base Template
  • Help Command
  • Embed Example
  1. Documentation

Examples

PreviousCreate a botNextContribute

Last updated 28 days ago


These examples assume that you have the Message Content privileged intent enabled. Follow step 4 on the guide.

Base Template

This is how the base code of your bot should like, but I recommend hiding the token better.

from dispy import Bot

token = 'your_token'
bot = Bot(token)

@bot.once('READY')
def on_ready():
   print('READY')

bot.run()

Help Command

To test your command, simply send !help in a channel that the bot has access to.

from dispy import Bot
from dispy.types import (
   Message,
   User
)

token = 'your_token'
bot = Bot(token)

@bot.once('READY')
def on_ready():
   print('READY')
   
@bot.on('MESSAGE_CREATE')
def on_message(msg: Message, user: User):
   if msg.content == '!help':
      msg.reply('My commands are:\n- !help - List the commands')

bot.run()

Embed Example

This is a basic example of the embed functionality, to see your embed, simply send !help in a channel that the bot has access to.

from dispy import Bot, EmbedBuilder
from dispy.types import (
   Message,
   User
)

token = 'your_token'
bot = Bot(token)

@bot.once('READY')
def on_ready():
    print('READY')
   
@bot.on('MESSAGE_CREATE')
def on_message(msg: Message, user: User):
    if msg.content == '!help':
        helpCommand = (EmbedBuilder()
            .setTitle('Commands List')
            .setColor('blue')
            .addField('!help', 'List the commands')
        )
        msg.reply(embeds=helpCommand)

bot.run()

Create a bot