如何使我的discord.py机器人通过python-omegle库发送消息并侦听/ disconnect?

时间:2020-10-09 14:01:34

标签: python discord discord.py

所以我的机器人有个问题,除了三件事之外,其他所有东西都能正常工作。

首先,该漫游器不会将在Discord上收到的消息作为聊天消息发送给Omegle。 其次,键入/ disconnect不会影响聊天。它什么也没做。 第三,聊天结束后,该机器人应该环回以查找新的聊天,但是它只是被卡住了,什么也不做。它完全没有响应,并且控制台中没有错误消息。如果聊天断开,我可能会完全结束循环,但是我不知道该怎么做。

这是代码:

@bot.command(
)
async def omegle(ctx, *args):
    args = ctx.message.content
    async def chat_loop(chat):
        while True:
            # Start a new chat every time the old one ends
            await ctx.send("Use /disconnect to disconnect from a chat.")
            print("- Starting chat -")
            await ctx.send("- Starting chat -")
            chat.start()
            while True:
                event, argument = chat.get_event()
                if event == ChatEvent.CHAT_WAITING:
                    print("- Waiting for a partner -")
                    await ctx.send("- Waiting for a partner -")
                elif event == ChatEvent.CHAT_READY:
                    print("- Connected to a partner -")
                    await ctx.send("- Connected to a partner -")
                    question = argument
                    print("- Discuss this question: {} -".format(question))
                    await ctx.send("**- Discuss this question: {} -**".format(question))
                elif event == ChatEvent.GOT_SERVER_NOTICE:
                    notice = argument
                    print("- Server notice: {} -".format(notice))
                    await ctx.send("- Server notice: {} -".format(notice))
                elif event == ChatEvent.PARTNER_STARTED_TYPING:
                    print("- Stranger started typing -")
                    await ctx.send("- Stranger started typing -")
                elif event == ChatEvent.PARTNER_STOPPED_TYPING:
                    print("- Stranger stopped typing -")
                    await ctx.send("- Stranger stopped typing -")
                elif event == ChatEvent.GOT_MESSAGE:
                    message = argument
                    print("Stranger: {}".format(message))    
                    await ctx.send("Stranger: {}".format(message))
                elif args == "/disconnect" or event == ChatEvent.CHAT_ENDED:
                    print("- Chat ended -")
                    chat.disconnect()
                    await ctx.send("**==============**")
                    await ctx.send("**- Chat ended -**")
                    await ctx.send("**==============**")
                else:
                    chat.send(args)
                    break
            break
    if __name__ == "__main__":
        chat = SpyeeChat()
        await chat_loop(chat=chat)

任何帮助将不胜感激!

0 个答案:

没有答案