简体   繁体   English

Discord.py | 如何根据输入的内容进行机器人对话?

[英]Discord.py | How to make a bot talk from what you put in input?

I want to make a bot that says what you put in input so like: 我想制作一个机器人,说出您输入的内容,例如:

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

I have tried doing this in many ways but I cannot get it to work and I cannot find anything online. 我已经尝试了许多方法来执行此操作,但是我无法使其正常工作,也无法在网上找到任何内容。 Help would be very appreciated! 帮助将不胜感激!

client.say won't work in the on_ready event. client.say不会在工作on_ready事件。 It can only be used from commands. 它只能在命令中使用。 See documentation here: http://discordpy.readthedocs.io/en/latest/faq.html#can-i-use-bot-say-in-other-places-aside-from-commands 请参阅此处的文档: http : //discordpy.readthedocs.io/en/latest/faq.html#can-i-use-bot-say-in-other-places-aside-from-commands

So instead, you can use client.send_message . 因此,您可以使用client.send_message This needs to take channel as an argument. 这需要以channel为参数。 Below is example code where the input will always be sent to the "general" 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM