blob: 4d828b41eeedc1743f4534a03e766d40933c566a (
plain)
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
50
51
52
53
54
55
56
57
|
import discord
import yaml
import datetime
from discord_slash import SlashContext, SlashCommand
from discord.ext.commands import Bot
from models.user import User
with open("config.yaml", "r") as yamlfile:
config = yaml.load(yamlfile, Loader=yaml.CLoader)
print("Read config successful")
config = config
intents = discord.Intents.default()
intents.members = True
bot = Bot(command_prefix="!", self_bot=True, intents=intents)
slash = SlashCommand(bot, sync_commands=True)
# Runs once bot has connected to discord
@bot.event
async def on_ready():
time_now = datetime.datetime.utcnow()
print(f"{time_now}: {bot.user} has connected to Discord!")
for guild in bot.guilds:
if guild.id == config["discord_server_id"]:
print(f"{time_now}: {bot.user} has joined {guild.name}!")
for channel in guild.channels:
if channel.name == config["discord_channel"]:
print(f"{time_now}: Found channel {channel.name}!")
@bot.event
async def on_message(message):
print(message.author.id)
user = User.get(User.discord_id == message.author.id)
user.add_message()
print(user.display_name)
@slash.slash(
name="test",
description="This is just a test command, nothing more.",
guild_ids=[config["discord_server_id"]],
)
async def test(ctx: SlashContext):
print("test")
await ctx.send(content="Beep boop")
bot.load_extension("commands.economy")
bot.load_extension("commands.basic_games")
bot.run(config["discord_token"])
|