【问题标题】:Discord.py | How to make a bot talk from what you put in input?不和谐.py |如何让机器人根据你输入的内容说话?
【发布时间】:2018-05-06 23:48:15
【问题描述】:

我想制作一个机器人,它可以说出您输入的内容,如下所示:

@client.event
async def on_ready():
    print("Ready when you are")
    while True:
       bop = input("")
       await client.say(bop)

我已经尝试过很多方法,但我无法让它工作,我在网上找不到任何东西。非常感谢您的帮助!

【问题讨论】:

  • 您将注册一个 on_message 协程,每当机器人观察到消息时就会调用该协程。 See this example bot from the discord.py github 一旦你对这个库更熟悉了,你可能需要考虑使用命令扩展,这取决于你想让你的机器人做什么。

标签: python-3.x discord.py


【解决方案1】:

client.sayon_ready 事件中不起作用。它只能从命令中使用。请参阅此处的文档:http://discordpy.readthedocs.io/en/latest/faq.html#can-i-use-bot-say-in-other-places-aside-from-commands

因此,您可以改用client.send_message。这需要将channel 作为参数。下面是示例代码,其中输入将始终发送到“通用”通道。

@client.event
async def on_ready():
    print("Ready when you are")
    while True:
        bop = input("")
        for server in client.servers:
            for channel in server.channels:
                if channel.name == "general":
                    await client.send_message(channel, bop)

【讨论】:

    猜你喜欢
    • 2020-06-20
    • 2020-09-01
    • 2022-11-22
    • 2021-07-07
    • 2021-09-26
    • 2022-01-11
    • 2018-07-07
    • 2021-03-03
    • 2017-09-14
    相关资源
    最近更新 更多