oooo o8o oooo o8o 光 2.0.0.dev101 [HEAD]
`888 `"' `888 `"' © 2021 davfsa - MIT license /home/nekokatt/code/hikari
888 .oo. oooo 888 oooo .oooo. oooo d8b oooo interpreter: CPython 3.8.10
888P"Y88b `888 888 .8P' `P )88b `888""8P `888 running on: x86_64 Linux 5.8.0-59-generic
888 888 888 888888. .oP"888 888 888 installed at: /home/nekokatt/code/hikari
888 888 888 888 `88b. d8( 888 888 888 documentation: https://www.hikari-py.dev/hikari
o888o o888o o888o o888o o888o `Y888""8o d888b o888o support: https://discord.gg/Jx4cNGG
I 2020-07-15 16:45:11,476 hikari: single-sharded configuration -- you have started 29/1000 sessions prior to connecting (resets at 16/07/20 11:38:05 BST)
I 2020-07-15 16:45:11,779 hikari.gateway.0: received HELLO, heartbeat interval is 41.25s
I 2020-07-15 16:45:11,958 hikari.gateway.0: shard is ready [session:1aa5f3fde733687ae7b41b1b55b29792, user_id:572144340277919754, tag:hikari#5863]
^C
Terminated 13897
[nekokatt@pc ~/hikari ] $ cat bot.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import asyncio
import functools
import os
import hikari
bot = hikari.Bot(token=os.environ["BOT_TOKEN"])
def command(name):
def decorator(fn):
@functools.wraps(fn)
async def wrapper(event):
content = event.message.content
if event.is_human and content is not None and content.startswith(name):
await fn(event)
return wrapper
return decorator
@bot.listen()
@command("hk.ping")
async def ping(event: hikari.MessageCreateEvent) -> None:
await event.message.respond("Pong!")
@bot.listen()
@command("hk.add")
async def add_numbers(event: hikari.MessageCreateEvent) -> None:
def is_number_check(e):
return (
event.message.author == e.message.author
and event.message.channel_id == e.message.channel_id
and e.message.content
and e.message.content.isdigit()
)
try:
await event.message.respond("Please enter the first number")
e1 = await bot.wait_for(hikari.MessageCreateEvent, predicate=is_number_check, timeout=30)
await event.message.respond("Please enter the second number")
e2 = await bot.wait_for(hikari.MessageCreateEvent, predicate=is_number_check, timeout=30)
except asyncio.TimeoutError:
await event.message.respond("You took too long...")
else:
val1 = int(e1.message.content)
val2 = int(e2.message.content)
embed = hikari.Embed(title="Result!", description=f"{val1} + {val2} = {val1 + val2}", color="#3f3")
await event.message.respond(embed=embed)
bot.run()
pip install
hikari
A new, powerful, static-typed Python API for writing Discord bots.
This API is still in an alpha state, and is a work in progress! Features may change
or undergo improvements before the design is finalized. Until then, why not join our Discord? Feel free
to drop in to ask questions, get updates on progress, and be able to provide valuable contributions and
feedback.
Tutorials, tips, and additional resources will come soon!
Slide into our server