From e94081b747b2cb9f919351bb5091a35e25f5f47f Mon Sep 17 00:00:00 2001 From: deflax Date: Mon, 15 Jan 2024 05:07:15 +0200 Subject: [PATCH] test discord.py --- src/discordbot/app.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/discordbot/app.py b/src/discordbot/app.py index 9550169..5038b29 100644 --- a/src/discordbot/app.py +++ b/src/discordbot/app.py @@ -1,23 +1,27 @@ import os import discord -from discord.ext import commands # Read env variables bot_token = os.environ.get('DISCORDBOT_TOKEN', 'token') scheduler_hostname = os.environ.get('SCHEDULER_API_HOSTNAME', 'tv.example.com') -# Create a bot instance with a command prefix -bot = commands.Bot(command_prefix='!') +# Intents +intents = discord.Intents.default() +intents.message_content = True -# Define a simple command -@bot.command(name='about', help='Displays about info') -async def hello(ctx): - await ctx.send(f'Hello {ctx.author.name}! ') +client = discord.Client(intents=intents) # Define an event when the bot is ready -@bot.event +@client.event async def on_ready(): - print(f'Logged in as {bot.user.name}') + print(f'Logged in as {client.user}') -# Run the bot with your bot token -bot.run(bot_token) \ No newline at end of file +@client.event +async def on_message(message): + if message.author == client.user: + return + + if message.content.startswith('!hello'): + await message.channel.send('Hello!') + +client.run(bot_token) \ No newline at end of file