-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.py
33 lines (23 loc) · 1.11 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import contextlib
import asyncio
from interactions import Client, Intents, listen, slash_command, SlashContext
from dotenv import load_dotenv
load_dotenv() # load the .env file
bot = Client(intents=Intents.DEFAULT)
# intents are what events we want to receive from discord, `DEFAULT` is usually fine
@listen() # this decorator tells interactions.py that it needs to listen for the corresponding event, and run this coroutine
async def on_ready():
# This event is called when the bot is ready to respond to commands
print("Ready")
print(f"This bot is owned by {bot.owner}")
@slash_command() # this decorator tells interactions.py to make a slash command with the corresponding name
async def ping(ctx: SlashContext):
# slash commands are always passed a SlashContext object, used to actually respond to the command
await ctx.send("Pong!") # send a message to the channel the command was used in
async def main():
bot.load_extensions("exts")
await bot.astart(os.environ["BOT_TOKEN"])
if __name__ == "__main__":
with contextlib.suppress(KeyboardInterrupt):
asyncio.run(main())