一个相对简单的命令,它需要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
实际结果:“出了点问题”
答案 0 :(得分: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和您要写入的频道。