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__/ __pycache__/
bot.conf
*.log

View File

@@ -1,5 +1,5 @@
{ {
"token": "your-token", "token": "OTExNTkwODQxMTgzNzY0NTMx.YZjnIQ.wsu4-3qnBJF2gI-9ZIV74SinBnw",
"name": "Template Bot", "name": "Template Bot",
"description": "Template for a Discord Bot", "description": "Template for a Discord Bot",
"author": "Template", "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 ## Imports
import discord
import json import json
from discord.ext import commands
from lib.keep_alive import keep_alive from lib.keep_alive import keep_alive
from lib.help import *
## Vars ## Vars
client = discord.Client() with open("bot.conf", 'r') as f:
with open("bot.json", 'r') as f:
BOTDATA = json.load(f) BOTDATA = json.load(f)
bot = commands.Bot(command_prefix=BOTDATA['prefix'])
## Run ## Run
@client.event ### Events
@bot.event
async def on_ready(): async def on_ready():
print('Logged in as {0.user}'.format(client)) print(f'Logged in as {bot.user}')
@client.event for guild in bot.guilds:
async def on_message(message): print(f'Connect to Server {guild.name} (id: {guild.id})')
if message.author == client.user:
return
if message.content.startswith(BOTDATA['prefix'] + 'help'): ### Commands
help = get_help() @bot.command(name='hello', help='Say hello!')
await message.channel.send(help) 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'): #keep_alive()
await message.channel.send('Hello!') bot.run(BOTDATA['token'])
keep_alive()
client.run(BOTDATA['token'])