GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • SwiBots
  • Docs
  • GitHub
  • PyPi
  • Basic Concepts
  • Fundamentals
  • Interactions
  • MiniApps
  • API Reference
  • Example
  • Calculator Bot Example
  • Creating Your First Bot: Echo Bot
  • Mini App Bot Example
  • Poll Bot Example

This view

  • Original page
  • New address

GeezerVison is showing switchcollab.github.io — Creating Your First Bot: Echo Bot | Swibots

In this example, we'll create a simple echo bot using SwiBots. This bot will respond to any message it receives by sending the same message back to the user.

Prerequisites​

Before you begin, make sure you have:

  1. Installed SwiBots (pip install swibots)
  2. Obtained a bot token from the Switch platform

The Code​

Here's the complete code for our echo bot:

from swibots import Client, BotContext, MessageEvent

app = Client("YOUR_BOT_TOKEN")

@app.on_message()
async def message_handler(ctx: BotContext[MessageEvent]):
message = ctx.event.message
await message.respond(f"Received: {message.message}")


app.run()

Running the Bot​

To run the bot, simply execute the script:

python echo_bot.py

Testing the Bot​

  • Prerequisites
  • The Code
  • Running the Bot
  • Testing the Bot
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.