send_message() gets called from a thread. Since my_channel.send() is async, I think it is necessary to have a synchronous send_message() call the asynchronous asend_message(). How can it be done?
#@typechecked
class MessageCog(Cog):
@typechecked
async def asend_message(self, message:str)->str:
my_channel:TextChannel = self.bot.get_channel(self.channel)
assert isinstance(my_channel, TextChannel)
embed :Embed = Embed(title="Response", description=message, color=pepe_green)
assert isinstance(embed, Embed)
my_message:Message = await my_channel.send(embed=embed)
assert isinstance(my_message, Message)
result :str = str(my_message) # ??
assert isinstance(result, str)
if not isinstance(result, str): raise Exception()
return result
@typechecked
def send_message(self, message:str)->str:
#
#f:Coroutine = lambda m: self.asend_message(m)
#result:str = run(f)
#
#result:str = run(self.asend_message(message))
#
#result:str = get_running_loop().run_untilcomplete(self.asend_message(message))
#
#f:Callable[[str],str] = async_to_sync(MessageCog.asend_message)
#
#f = async_to_sync(MessageCog.asend_message)
#result:str = f(self, message)
#
#result:str = create_task(self.asend_message(message))
#
#f = partial(MessageCog.asend_message, self)
#result:str = run(f(message))
assert isinstance(result, str)
if not isinstance(result, str): raise Exception()
return result
Errors are always the same:
[chain/error] [chain:AgentExecutor] [82.96s] Chain run errored with error:
...
TypeError: type of the return value must be str; got coroutine instead