-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
41 lines (32 loc) · 954 Bytes
/
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
34
35
36
37
38
39
40
41
from typing import Final
import os
import keyboard
from dotenv import load_dotenv
from discord import Intents, Client
load_dotenv()
TOKEN: Final[str] = os.getenv('DISCORD_TOKEN')
SESSION: Final[int] = int(os.getenv('SESSION')
intents: Intents = Intents.default()
intents.message_content = True
client: Client = Client(intents=intents)
async def send_message() -> None:
try:
channel = client.get_channel(SESSION)
if channel:
response = "hello there how are you!"
await channel.send(response)
else:
print("channel not found")
except Exception as e:
print(e)
@client.event
async def on_ready():
print("bot is ready!")
def on_space_press():
client.loop.create_task(send_message())
keyboard.on_release_key("space", lambda _: on_space_press())
await send_message()
def main() -> None:
client.run(token=TOKEN)
if __name__ == "__main__":
main()