python - 报告命令通道
问题描述
我有用于报告命令的机器人代码,但我希望它将所有内容都放在命令所在的频道中
@bot.command()
async def report(ctx):
a_list = []
submit_channel = bot.get_channel(889700840913371166)
channel = await ctx.author.create_dm()
def check(m):
return m.content is not None and m.channel == channel
for question in q_list:
await asyncio.sleep(1)
await channel.send(question)
msg = await bot.wait_for('message', check=check)
a_list.append(msg.content)
submit_wait = True
while submit_wait:
await channel.send('End of questions - "submit" to finish')
msg = await bot.wait_for('message', check=check)
if "submit" in msg.content.lower():
submit_wait = False
answers = "\n".join(f'{a}. {b}' for a, b in enumerate(a_list, 1))
submit_msg = f'Application from {msg.author} \nThe answers are:\n{answers}'
await submit_channel.send(submit_msg)
解决方案
我不知道这是不是你的要求。但是要向最初发送命令的通道发送消息,您可以:
@bot.command(pass_context=True)
async def report(ctx):
await ctx.send("Message to the original channel!")
另外,我想补充一点,discord.py 库已存档,因此将来对 api 的更改可能会使 discord.py 不起作用。
推荐阅读
- c++ - 奇怪的班级演员发生
- express - 如何防止在 API 端点服务器端多次点击?
- c# - 发送数据时,模型中的布尔字段未在控制器中更新
- c# - 将子域映射到 ASP.Net Core 3 中的区域
- iis-7.5 - 内部 II(S) 网站适用于 HTTP(S),但不适用于 HTTP
- python - LSQ 子问题中的奇异矩阵 C 错误
- typescript - ionic 4 - 获取离子切换值作为文本输入并在选择一个选项时关闭所有其他开关
- azure-devops - Azure-DevOps 克隆将引用显示为警告
- excel - 创建数据透视表:错误 - 数据透视表字段名称无效
- scala - 如何使用 Scala Spark 快速处理数百万个小型 JSON 文件?