This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiscordbot.py
49 lines (36 loc) · 1.51 KB
/
discordbot.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
42
43
44
45
46
47
48
49
import asyncio
import discord
import log
def SetupDiscordClient(aipiaqueue: asyncio.Queue, routerqueue: asyncio.Queue, user_id: int) -> discord.Client:
client = discord.Client(intents = discord.Intents.all())
@client.event
async def on_ready() -> None:
print(f"Logged onto discord under the username {client.user}. Attempting to fetch the user.")
DiscordUser = client.get_user(user_id)
if(DiscordUser is not None):
print("We have the user!")
if (DiscordUser.dm_channel is None):
print("No DM Channel yet, creating one!")
await DiscordUser.create_dm()
await client.change_presence(status = discord.Status.idle, activity = discord.CustomActivity(name = "Just woke up!"))
else:
print("Unable to get the user?\nThrowing exception.")
raise Exception("Unable to aquire the user.")
@client.event
async def on_message(message: discord.Message) -> None:
if message.author == client.user:
return
if message.author.id != user_id:
return
#Overload if you'd like - probably not going to use this for a while
if message.content.startswith("!"):
log.EscapedIncomingMessage(message)
return
try:
log.IncomingDiscordMessage(message)
await aipiaqueue.put(message)
except Exception as e:
await message.channel.send("Please let me (Isabelle) know when you saw this. There's an error in the discord bot code!")
print("Specific error:")
print(e)
return client