test discord.py
This commit is contained in:
parent
13fb4161bf
commit
e94081b747
1 changed files with 15 additions and 11 deletions
|
@ -1,23 +1,27 @@
|
||||||
import os
|
import os
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
|
||||||
|
|
||||||
# Read env variables
|
# Read env variables
|
||||||
bot_token = os.environ.get('DISCORDBOT_TOKEN', 'token')
|
bot_token = os.environ.get('DISCORDBOT_TOKEN', 'token')
|
||||||
scheduler_hostname = os.environ.get('SCHEDULER_API_HOSTNAME', 'tv.example.com')
|
scheduler_hostname = os.environ.get('SCHEDULER_API_HOSTNAME', 'tv.example.com')
|
||||||
|
|
||||||
# Create a bot instance with a command prefix
|
# Intents
|
||||||
bot = commands.Bot(command_prefix='!')
|
intents = discord.Intents.default()
|
||||||
|
intents.message_content = True
|
||||||
|
|
||||||
# Define a simple command
|
client = discord.Client(intents=intents)
|
||||||
@bot.command(name='about', help='Displays about info')
|
|
||||||
async def hello(ctx):
|
|
||||||
await ctx.send(f'Hello {ctx.author.name}! ')
|
|
||||||
|
|
||||||
# Define an event when the bot is ready
|
# Define an event when the bot is ready
|
||||||
@bot.event
|
@client.event
|
||||||
async def on_ready():
|
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
|
@client.event
|
||||||
bot.run(bot_token)
|
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)
|
Loading…
Reference in a new issue