recode as commands.Bot instead of discord.client

This commit is contained in:
2021-11-21 14:19:14 +01:00
parent e9730cbf2f
commit 8864543129
2 changed files with 15 additions and 33 deletions

41
main.py
View File

@@ -15,44 +15,33 @@
####################
## Imports
import discord
import json
from discord.ext import commands
from lib.keep_alive import keep_alive
from lib.help import *
## Vars
client = discord.Client()
with open("bot.conf", 'r') as f:
BOTDATA = json.load(f)
bot = commands.Bot(command_prefix=BOTDATA['prefix'])
## Run
@client.event
### Events
@bot.event
async def on_ready():
print('Logged in as {0.user}'.format(client))
print(f'Logged in as {bot.user}')
for guild in client.guilds:
for guild in bot.guilds:
print(f'Connect to Server {guild.name} (id: {guild.id})')
@client.event
async def on_message(message):
if message.author.bot:
return
if message.content.startswith(BOTDATA['prefix'] + 'help'):
help = get_help()
await message.channel.send(help)
if message.content.startswith(BOTDATA['prefix'] + 'hello'):
await message.channel.send("Hello, {}!".format(message.author))
@client.event
async def on_error(event, *args, **kwargs):
with open('err.log', 'a') as f:
if event == 'on_message':
f.write(f'Unhandled message: {args[0]}\n')
else:
raise
### Commands
@bot.command(name='hello', help='Say hello!')
async def say_hello(ctx):
await ctx.send(f'Hello, <@{ctx.author.id}>!')
print(ctx.guild)
print(ctx.message.content)
print(ctx.message)
print(ctx.author)
#keep_alive()
client.run(BOTDATA['token'])
bot.run(BOTDATA['token'])