Compare commits

...

10 Commits

Author SHA1 Message Date
8864543129 recode as commands.Bot instead of discord.client 2021-11-21 14:19:14 +01:00
e9730cbf2f add ignore log files 2021-11-20 20:04:29 +01:00
3434c0171e add error catch 2021-11-20 20:04:00 +01:00
46c168391b dont react on messages from bots 2021-11-20 19:56:15 +01:00
77767a9fb4 dont react on messages from bots 2021-11-20 19:55:12 +01:00
24e35a2b91 add list of connected servers on startup 2021-11-20 19:16:42 +01:00
43b6aa067c add username to hello message 2021-11-20 18:45:00 +01:00
c5e69d7b15 cleanup bot.json 2021-11-20 18:44:12 +01:00
95603a3907 add bot.conf 2021-11-20 18:43:41 +01:00
8343e0cde2 Rename bot.json to bot.conf 2021-11-20 18:43:08 +01:00
4 changed files with 22 additions and 26 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
__pycache__/
bot.conf
*.log

View File

@@ -1,5 +1,5 @@
{
"token": "your-token",
"token": "OTExNTkwODQxMTgzNzY0NTMx.YZjnIQ.wsu4-3qnBJF2gI-9ZIV74SinBnw",
"name": "Template Bot",
"description": "Template for a Discord Bot",
"author": "Template",

View File

@@ -1,7 +0,0 @@
def get_help():
help = """
__**Help**__ \n
Prefix: $
hello: get a hello back
"""
return(help)

37
main.py
View File

@@ -15,32 +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.json", 'r') as f:
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}')
@client.event
async def on_message(message):
if message.author == client.user:
return
for guild in bot.guilds:
print(f'Connect to Server {guild.name} (id: {guild.id})')
if message.content.startswith(BOTDATA['prefix'] + 'help'):
help = get_help()
await message.channel.send(help)
### 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)
if message.content.startswith(BOTDATA['prefix'] + 'hello'):
await message.channel.send('Hello!')
keep_alive()
client.run(BOTDATA['token'])
#keep_alive()
bot.run(BOTDATA['token'])