【问题标题】:How do I make my python discord bot say the same message every 0.10 seconds如何让我的 python discord bot 每 0.10 秒说出相同的消息
【发布时间】:2020-08-08 19:03:59
【问题描述】:

在我的不和谐服务器中进行了一场比赛,要在 24 小时内说出最多的消息。我不想手动做,所以我决定创建一个机器人。当我现在说什么但我想让它重复时,机器人可以发送消息。

**import discord
client = discord.Client()
@client.event
async def on_message(message):
    message.content.lower()
    if message.author == client.user:
        return
    if message.content.startswith("test"):
        await message.channel.send("example")
client.run('TOKEN')**

【问题讨论】:

  • 哈哈,你会赢的!
  • 您可以导入时间,将消息部分放入循环结束时的while循环中放入time.sleep(amount_time)并运行它应该可以工作。 “发送消息”....“等待”....“发送消息”。你试过了吗?

标签: python discord


【解决方案1】:
from time import sleep
while True:
    message.channel.send("message")
    sleep(.1) # time.sleep takes time in seconds 

【讨论】:

  • 它显示“回溯(最近一次通话):文件“C:/Users/My Computer/Desktop/nwor/nworl.py”,第 7 行,在 message.channel.send ("message") NameError: name 'message' is not defined"
  • 请不要只发布代码作为答案,还要解释您的代码的作用以及它如何解决问题的问题。带有解释的答案通常更有帮助,质量更高,更有可能吸引投票。
猜你喜欢
  • 2019-03-23
  • 2018-11-21
  • 2021-12-17
  • 2019-06-07
  • 2020-12-24
  • 2021-03-27
  • 2020-04-25
  • 1970-01-01
  • 2018-05-03
相关资源
最近更新 更多