I have quite a large bot for Discord written up. It has over 1000 lines of code. When I researched how to do it on Youtube and here, nothing seems to be working. I was wondering if someone could explain how to use a cog properly, possibly with photo examples. I can show what code I have to help you understand what I want.
An example would be that I want to have all of my mod commands in a separate file, just so its cleaner and more organized. so, how do I go about doing this? Here is an example of my code:
Mod Commands I want to move to a separate file using a cog
#kick Command
@bot.command(pass_context=True)
@commands.has_role("BotUser")
async def kick(ctx, user: discord.Member):
await bot.say(":boot:{} has been kicked from the server... Too bad...".format(user.name))
await bot.kick(user)
await bot.delete_message(ctx.message)
#Ban Command
@bot.command(pass_context=True)
@commands.has_role("BotUser")
async def ban(ctx, user: discord.Member):
await bot.say(":rofl: {} has been banned until further notice... Sucks to Suck")
await bot.ban(user)
await bot.delete_message(ctx.message)
#Clear command (Can only clear messages over 14 days old!)
@bot.command(pass_context=True)
@commands.has_role("BotUser")
async def clear(ctx, amount=100):
channel = ctx.message.channel
messages = []
async for message in bot.logs_from(channel, limit=int(amount) + 1):
messages.append(message)
await bot.delete_messages(messages)
await bot.delete_message(ctx.message)
Imports currently that I have
import discord
from discord.ext import commands
from discord.ext.commands import Bot
import asyncio
import json
import os
Prefix and directory
bot = commands.Bot(command_prefix='.')
bot.remove_command('help')
players = {}
queues = {}
os.chdir(r"C:\Users\anakr\Documents\DiscordBots\Bot Test")
Calling token ID - token id is above, not shown:
bot.run(TOKEN)
I am unsure how to start a cog completely, what else to import, how to call the file. I know Java well, but I am trying to work on my python skills with Discord.