Как загрузить команды из нескольких файлов Python Bot ниже - это мой main.py и другие файлы python с командами.Это правильный метод или мне нужно что-то изменить?мне нужно добавить token
, prefix
, bot = commands.Bot
, bot.run(token)
и т. д. во все файлы.
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))