代码之家  ›  专栏  ›  技术社区  ›  Mooles

如何修复此代码以发送到reported

  •  -2
  • Mooles  · 技术社区  · 7 年前

    一个相对简单的命令,它接受3个参数(reportedtag、reportertag和reasons),目的是从 报告书 并发送一个给 #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")  
    

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

    实际结果:“出了问题”

    1 回复  |  直到 7 年前
        1
  •  1
  •   AlexINF    7 年前

    有两件事不对:

    有个问题 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 是假的。请检查你的身份证和你正在写的频道。