How to load commands from multiple files Python Bot below is my main.py and other python files with commands. Is this correct method or do i need to change anything? do i need to add token
, prefix
, bot = commands.Bot
, bot.run(token)
etc in all files.
main.py
token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
prefix = "?"
import discord
from discord.ext import commands
startup_extensions = ["second", "third"]
bot = commands.Bot(command_prefix=prefix)
bot.remove_command("help")
@bot.event
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command(pass_context=True)
async def hello1(ctx):
msg = 'Hello {0.author.mention}'.format(ctx.message)
await bot.say(msg)
bot.run(token)
second.py
import discord
from discord.ext import commands
class Second():
def __init__(self, bot):
self.bot = bot
@commands.command(pass_context=True)
async def hello2(ctx):
msg = 'Hello{0.author.mention}'.format(ctx.message)
await bot.say(msg)
def setup(bot):
bot.add_cog(Second(bot))
third.py
import discord
from discord.ext import commands
class Third():
def __init__(self, bot):
self.bot = bot
@commands.command(pass_context=True)
async def hello3(ctx):
msg = 'Hello{0.author.mention}'.format(ctx.message)
await bot.say(msg)
def setup(bot):
bot.add_cog(Third(bot))