【问题标题】:I tried to make a stair command in discord.py我试图在 discord.py 中创建一个楼梯命令
【发布时间】:2021-09-04 11:01:17
【问题描述】:

我尝试在 discord.py 中创建一个楼梯命令,它应该是这样的:

---
   I
----
    I

等等……

但我得到一个错误:

SyntaxError: 无效语法 PS E:\Hyper Bot> & C:/Users/merli/AppData/Local/Programs/Python/Python36-32/python.exe "e:/Hyper Bot/Hyper bot.py" 文件“e:/Hyper Bot/Hyper bot.py”,第 183 行 时间.睡眠 1 ^ SyntaxError: 无效语法

这是我的代码:

async def stairs(ctx):
   i = 1
   while True:
       ctx.send(i * '-')
       ctx.send(i * ' ' + 'I')
       i = i + 2
       time.sleep 1 ```

【问题讨论】:

  • time.sleep(1) 你缺少括号。
  • 你在ctx.send之前缺少await

标签: python discord command discord.py bots


【解决方案1】:

错误是time.sleep 1,因为正如约翰戈登指出的那样,缺少括号。但是我想补充一点,您根本不应该使用time.sleep

See time 是一个同步库,当您使用 time.sleep 时,您的整个机器人将进入休眠状态,不会响应用户或获取事件。

您应该改用await asyncio.sleep。它的使用方式相同,您导入的库与import asyncio 相同。

【讨论】:

  • 好的,这行得通,谢谢,但现在我有另一个错误:e:/Hyper Bot/Hyper bot.py:181: RuntimeWarning: coroutine 'Messageable.send' was never waiting ctx.send (i * '-') e:/Hyper Bot/Hyper bot.py:182: RuntimeWarning: coroutine 'Messageable.send' 从未等待 ctx.send(i * ' ' + 'I')
  • 阅读错误,它说“发送”从未等待过的东西。 await
猜你喜欢
  • 2020-08-02
  • 2021-08-09
  • 1970-01-01
  • 2021-06-20
  • 2022-10-07
  • 2020-08-30
  • 1970-01-01
  • 2019-06-30
  • 2021-06-07
相关资源
最近更新 更多