Simple Discord bot
This commit is contained in:
		
							
								
								
									
										8
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
.idea/
 | 
			
		||||
 | 
			
		||||
__pycache__/
 | 
			
		||||
*.pyc
 | 
			
		||||
venv/
 | 
			
		||||
 | 
			
		||||
config.yml
 | 
			
		||||
*.log
 | 
			
		||||
							
								
								
									
										37
									
								
								bot.py
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										37
									
								
								bot.py
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
#!/usr/bin/env python3
 | 
			
		||||
 | 
			
		||||
from dataclasses import dataclass
 | 
			
		||||
import discord
 | 
			
		||||
from discord.ext import commands
 | 
			
		||||
import logging
 | 
			
		||||
import yaml
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@dataclass
 | 
			
		||||
class Config:
 | 
			
		||||
    discord_token: str
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
with open('config.yml') as config_file:
 | 
			
		||||
    config = Config(**yaml.safe_load(config_file))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
logger = logging.getLogger('discord')
 | 
			
		||||
logger.setLevel(logging.DEBUG)
 | 
			
		||||
handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
 | 
			
		||||
handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
 | 
			
		||||
logger.addHandler(handler)
 | 
			
		||||
 | 
			
		||||
bot = commands.Bot(command_prefix='!')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@bot.event
 | 
			
		||||
async def on_message(message):
 | 
			
		||||
    await bot.process_commands(message)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@bot.command()
 | 
			
		||||
async def helloworld(ctx):
 | 
			
		||||
    await ctx.send("plop")
 | 
			
		||||
 | 
			
		||||
bot.run(config.discord_token)
 | 
			
		||||
							
								
								
									
										1
									
								
								config.yml.example
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								config.yml.example
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1 @@
 | 
			
		||||
discord_token: insert_token_here
 | 
			
		||||
							
								
								
									
										2
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								requirements.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
			
		||||
discord
 | 
			
		||||
pyyaml
 | 
			
		||||
		Reference in New Issue
	
	Block a user