如何更好地使用"def"函数而不给出“<function test_message at 0x7f5d198b3ca0>”错误?
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)
我用它来测试“def”函数,但是当我在 Discord 聊天中调用时,它发送的是“”而不是“testing”。有人能更好地解释一下如何设置吗?
ctx.send
获取您传递给它的对象并从中生成一个字符串。对于函数,您将获得该表示。
相反,您需要使 test_message
成为一个异步函数(这样您就可以在其中调用 ctx.send
等异步函数)并直接调用它。
async def test_message(ctx):
await ctx.send("testing")
@bot.command()
async def testa(ctx):
await test_message(ctx)
def test_message(ctx):
ctx.send("testing")
@bot.command()
async def testa(ctx):
await ctx.send(test_message)
我用它来测试“def”函数,但是当我在 Discord 聊天中调用时,它发送的是“
ctx.send
获取您传递给它的对象并从中生成一个字符串。对于函数,您将获得该表示。
相反,您需要使 test_message
成为一个异步函数(这样您就可以在其中调用 ctx.send
等异步函数)并直接调用它。
async def test_message(ctx):
await ctx.send("testing")
@bot.command()
async def testa(ctx):
await test_message(ctx)