0

Okay so I want to make a test command and have it run the output of a cog that I have called help.py. And I don't really know what to do here

My Code:

import discord
from discord.ext import commands
import help
@bot.command()
async def test(ctx, *, commands=None):
    if commands == help:
        exec(open('help.py').read())
    await ctx.send(f"{commands} has been ran. Does it work?")

I have no clue on how to make it "run" the file in a way and print the output into discord but I think I have it reading the file but I need it to run the help command inside of the test command and print to discord. Sorry if this is confusing

Wep
  • 7
  • 1
  • If I understand your question correctly you could use `eval()`. Please keep in mind that you should be very, very careful when using this with a discord bot as it could lead to all kinds of abuse. https://stackoverflow.com/questions/9383740/what-does-pythons-eval-do – moinierer3000 Apr 09 '22 at 12:50
  • What do you mean by "run the output of a cog"? Are you asking how to run another command inside this command? Some use case like, I have command `kick` and I also want to run `notify_moderator` in it? – Eric Jin Apr 09 '22 at 22:09
  • Thats exactly what i mean I just didnt know how to word it like that – Wep Apr 10 '22 at 16:02

0 Answers0