-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
40 lines (32 loc) · 984 Bytes
/
Copy pathmain.py
File metadata and controls
40 lines (32 loc) · 984 Bytes
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
import asyncio
import discord
from discord.ext import commands
from config import DISCORD_TOKEN, SERVER_ID
import threading
import sys
intents = discord.Intents.default()
intents.members = True
bot = commands.Bot(command_prefix="!", intents=intents)
@bot.event
async def on_ready():
guild = discord.Object(id=SERVER_ID)
bot.tree.copy_global_to(guild=guild)
await bot.tree.sync(guild=guild)
print(f"Logged in as {bot.user}")
def terminal_input():
while True:
cmd = input()
if cmd.lower() in ['q', 'quit', 'exit']:
asyncio.run_coroutine_threadsafe(bot.close(), bot.loop)
break
async def main():
thread = threading.Thread(target=terminal_input, daemon=True)
thread.start()
try:
async with bot:
await bot.load_extension("commands.roles")
await bot.start(DISCORD_TOKEN)
except KeyboardInterrupt:
await bot.close()
if __name__ == "__main__":
asyncio.run(main())