Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to better use the "def" function and not give "<function test_message at 0x7f5d198b3ca0>" error?

def test_message(ctx):
  ctx.send("testing")

@bot.command()
async def testa(ctx):
  await ctx.send(test_message)

I have this down to test the "def" function but when I call in inside a Discord chat it send, "<function test_message at 0x7f5d198b3ca0>" and not "testing". Could someone better explain how t set this up?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ctx.send takes the object you pass it and makes a string out of it. For functions, you’ll get that representation.

Instead, you’ll want to make test_message an async function (so you can call async functions such as ctx.send within it) and just call it.

async def test_message(ctx):
  await ctx.send("testing")

@bot.command()
async def testa(ctx):
  await test_message(ctx)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading