Closed holymode closed 11 months ago
For discord.py, the only major difference call in the GPTFunctionLibrary's add_in_commands method sometime before making a call to OpenAI. Decorated commands can be in any cog, and you should only need to do this once.
Like how coroutines use call_by_dict_async, to invoke a decorated discord.py command you need to use call_by_dict_ctx
which requires a commands.context object along with the function_dict.
essentially:
if not added:
mylib.add_in_commands(ctx.bot)
added=True
# After call to OpenAI
result=await mylib.call_by_dict_ctx(ctx,function_dict)
I'll add a dedicated discord.py example in the next version.
a dedicated example for discord.py bot commands has been added. check examples/discord_bot.py
Sorry for late response, was busy the couple of days.
My issue is more like
Unresolved attribute reference 'add_in_commands' for class 'MyLib'
if I try to add it.
And what if my functions are mixed, like non discord one with discord ones, do you still call call_by_dict_ctx? Since there is no way of knowing what function might be invoked.
1:
Unresolved attribute reference 'add_in_commands' for class 'MyLib'
should only happen if the discord.py library is not installed.
2: you still use call_by_dict_ctx
if you mixed non discord functions with discord functions.
I feel like it needs a better example for discord.py when your commands are in different cogs. Since you probably don't want to add all commands as functions. I tried to add, but it would never be recognized as a function.
Looked at your bot, but was not much of a help.
An example would be much appreciated.