如何修复此代码以发送到#报告

2024-10-01 00:15:14 发布

您现在位置:Python中文网/ 问答频道 /正文

一个相对简单的命令,它有3个参数(reportedTag、reporterTag和reasons),目的很简单,就是从#report中删除消息并发送一个到#reported我的问题是它看不到原始命令,因此不发送报告的消息

我试过使用频道ID,频道名称,但是没有用

#---Report Command---#
@bot.command(pass_context=True)
async def report(ctx,  reportedTag, reporterTag, *reasons):

  if int(ctx.message.channel.id) == 416164062901305345:
    reason = ' '.join(reasons)
    await bot.delete_message(ctx.message)   
    mesg = "Report by "+ reporterTag +  " for " + reportedTag + "Reason is: " + reason
    return await bot.say("Report recieved. Staff have been notified :)\nEnjoy your day and we'll take care of this")
    return await bot.send_message(bot.get_channel("534496148149370900"), mesg)
  else:
      print ("Something went wrong")  

预期结果:命令行从#报告中删除,消息发送到#报告

实际结果:“出事了”


Tags: 命令report消息messagebot报告channelawait
1条回答
网友
1楼 · 发布于 2024-10-01 00:15:14

有两件事不对:

在代码中使用的return语句中有一个问题return退出子例程,因此bot.send_message(bot.get_channel("534496148149370900"), mesg)行实际上从未被调用。所以你的代码应该改成这样:

# -Report Command -#
@bot.command(pass_context=True)
async def report(ctx,  reportedTag, reporterTag, *reasons):

if int(ctx.message.channel.id) == 416164062901305345:
    reason = ' '.join(reasons)
    await bot.delete_message(ctx.message)   
    mesg = "Report by "+ reporterTag +  " for " + reportedTag + "Reason is: " + reason
    await bot.send_message(bot.get_channel("534496148149370900"), mesg)
    return await bot.say("Report recieved. Staff have been notified :)\nEnjoy your day and we'll take care of this")
else:
    print ("Something went wrong") 

除此之外,如果“出事了”实际上是输出的,那就意味着int(ctx.message.channel.id) == 416164062901305345是假的。请检查你的身份证和你正在写的频道

相关问题 更多 >