Fix background script
bot = hikari.Bot(token=os.environ["BOT_TOKEN"])
+
def command(name):
def decorator(fn):
@functools.wraps(fn)
async def wrapper(event):
if not event.message.author.is_bot and event.message.content.startswith(name):
await fn(event)
+
return wrapper
+
return decorator
+
@bot.listen()
@command("hk.ping")
- async def ping(message: hikari.MessageCreateEvent) -> None:
+ async def ping(event: hikari.MessageCreateEvent) -> None:
await event.message.reply("Pong!")
- @bot.event()
+
+ @bot.listen()
@command("hk.add")
async def add_numbers(event: hikari.MessageCreateEvent) -> None:
- await event.message.reply("Please enter the first number")
-
def is_number_check(e):
- return event.message.author == e.message.author and e.message.content.isdigit()
+ return (
+ event.message.author == e.message.author
+ and event.message.channel_id == e.message.channel_id
+ and e.message.content.isdigit()
+ )
try:
- e1 = await bot.wait_for(MessageCreateEvent, predicate=is_number_check, timeout=30)
- await event.reply("Please enter the second number")
- e2 = await bot.wait_for(MessageCreateEvent, predicate=is_number_check, timeout=30)
+ await event.message.reply("Please enter the first number")
+ e1 = await bot.wait_for(hikari.MessageCreateEvent, predicate=is_number_check, timeout=30)
+ await event.message.reply("Please enter the second number")
+ e2 = await bot.wait_for(hikari.MessageCreateEvent, predicate=is_number_check, timeout=30)
except asyncio.TimeoutError:
await event.message.reply("You took too long...")
val1 = int(e1.message.content)
val2 = int(e2.message.content)
- embed = hikari.Embed(title="Result!", description=f"{val1} + {val2}" color="#3f3")
+ embed = hikari.Embed(title="Result!", description=f"{val1} + {val2} = {val1 + val2}", color="#3f3")
await event.message.reply(embed=embed)
+
bot.run()
</code>
</pre>
