首页 > 解决方案 > 报告命令通道

问题描述

我有用于报告命令的机器人代码,但我希望它将所有内容都放在命令所在的频道中

@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)

标签: python

解决方案


我不知道这是不是你的要求。但是要向最初发送命令的通道发送消息,您可以:

@bot.command(pass_context=True)
async def report(ctx):
    await ctx.send("Message to the original channel!")

另外,我想补充一点,discord.py 库已存档,因此将来对 api 的更改可能会使 discord.py 不起作用。


推荐阅读