Home > front end >  How to better use the "def" function and not give "<function test_message at 0x7f5
How to better use the "def" function and not give "<function test_message at 0x7f5

Time:02-13

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?

CodePudding user response:

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)
  • Related