【问题标题】:How do I fix this code to sent to #reported如何修复此代码以发送到#reported
【发布时间】:2019-01-15 21:38:36
【问题描述】:

一个相对简单的命令,它采用 3 个参数(reportedTag、reporterTag 和原因),其简单目的是从 #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")  

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

实际结果:“出了点问题”

【问题讨论】:

  • 应该发生的是它会发送这样的消息:Report by @IGA for @Hoe Hoe Hoe 2 Point O Reason is: being mean and swearing lots and lots 它以前可以工作,但是在添加 if/else 语句后它不再发送消息
  • 显然int(ctx.message.channel.id) 不等于 416164062901305345。为什么你认为它应该是?
  • 当在#report 文本通道中执行命令时,将返回单独的命令!channel 416164062901305345。

标签: python python-3.x discord.py


【解决方案1】:

两件事错了:

您在代码中使用的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 是假的。请检查您正在写入的 ID 和频道。

【讨论】:

  • Cheers Alex :) 现在效果很好。我在这个过程中学到了一些新东西。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-10
  • 1970-01-01
  • 2015-12-12
  • 2021-07-24
  • 1970-01-01
  • 2023-03-11
相关资源
最近更新 更多