python - 不和谐机器人(-功能像学校的钟声)
问题描述
我的想法是制作不和谐机器人,它会像我们学校的钟声一样同时响起。在一天开始的时候,我写信给聊天!响开始计时我的课程,但它不起作用。
这是我的代码:
import asyncio
from discord.ext import commands
from discord import FFmpegPCMAudio
from discord.utils import get
import datetime
TOKEN = '####'
client = commands.Bot(command_prefix='!')
@client.event
async def on_ready():
print("Bot is ready")
@client.command()
async def ring(ctx):
now = datetime.datetime.now().strftime("%X")
channel = ctx.message.author.voice.channel
lessons = {"1.lesson": "8:10:00",
"2.lesson": "9:05:00",
"3.lesson": "10:00:00",
"4.lesson": "11:00:00",
"5.lesson": "11:55:00",
"6.lesson": "13:00:00",
"7.lesson": "13:55:00"}
await ctx.send(now)
await ctx.send(ctx.message.author.nick)
await ctx.send("activated!")
while 1:
datetime.datetime.now().strftime("%X")
# 1.hodina
if datetime.datetime.now().strftime("%X") == (lessons["6.lesson"]):
await ctx.send("crrrrrrrrrrr")
await ctx.send("crrrrrrrrrrr")
await channel.connect()
voice = get(client.voice_clients, guild=ctx.guild)
source = FFmpegPCMAudio('alarm.mp3')
voice.play(source)
await asyncio.sleep(14)
await ctx.guild.voice_client.disconnect()
start = 1
i = 0
break
while start == 1:
# 2.lesson
if i == 0:
await asyncio.sleep(3300)
await channel.connect()
voice = get(client.voice_clients, guild=ctx.guild)
source = FFmpegPCMAudio('alarm.mp3')
voice.play(source)
await asyncio.sleep(14)
await ctx.guild.voice_client.disconnect()
i = 1
# 3.lesson
if i == 1:
await asyncio.sleep(3300)
await channel.connect()
voice = get(client.voice_clients, guild=ctx.guild)
source = FFmpegPCMAudio('alarm.mp3')
voice.play(source)
await asyncio.sleep(14)
await ctx.guild.voice_client.disconnect()
i = 2
# 4.lesson
if i == 2:
await asyncio.sleep(3600)
await channel.connect()
voice = get(client.voice_clients, guild=ctx.guild)
source = FFmpegPCMAudio('alarm.mp3')
voice.play(source)
await asyncio.sleep(14)
await ctx.guild.voice_client.disconnect()
i = 3
# 5.lesson
if i == 3:
await asyncio.sleep(3300)
await channel.connect()
voice = get(client.voice_clients, guild=ctx.guild)
source = FFmpegPCMAudio('alarm.mp3')
voice.play(source)
await asyncio.sleep(14)
await ctx.guild.voice_client.disconnect()
i = 4
# 6.lesson
if i == 4:
await asyncio.sleep(3900)
await channel.connect()
voice = get(client.voice_clients, guild=ctx.guild)
source = FFmpegPCMAudio('alarm.mp3')
voice.play(source)
await asyncio.sleep(14)
await ctx.guild.voice_client.disconnect()
i = 5
# 7.lesson
if i == 5:
await asyncio.sleep(3300)
await channel.connect()
voice = get(client.voice_clients, guild=ctx.guild)
source = FFmpegPCMAudio('alarm.mp3')
voice.play(source)
await asyncio.sleep(14)
await ctx.guild.voice_client.disconnect()
start == 0
client.run(TOKEN)
这是控制台所说的:
Bot is ready
Bot is ready
Ignoring exception in command ring:
Traceback (most recent call last):
File "C:\Users\vitek\OneDrive\Dokumenty\Pycharm Projects\Discord_Bots\venv\lib\site-packages\discord\voice_client.py", line 329, in connect
await utils.sane_wait_for(futures, timeout=timeout)
File "C:\Users\vitek\OneDrive\Dokumenty\Pycharm Projects\Discord_Bots\venv\lib\site-packages\discord\utils.py", line 352, in sane_wait_for
raise asyncio.TimeoutError()
concurrent.futures._base.TimeoutError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\vitek\OneDrive\Dokumenty\Pycharm Projects\Discord_Bots\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:/Users/vitek/OneDrive/Dokumenty/Pycharm Projects/Discord_Bots/test.py", line 38, in ring
await channel.connect()
File "C:\Users\vitek\OneDrive\Dokumenty\Pycharm Projects\Discord_Bots\venv\lib\site-packages\discord\abc.py", line 1122, in connect
await voice.connect(timeout=timeout, reconnect=reconnect)
File "C:\Users\vitek\OneDrive\Dokumenty\Pycharm Projects\Discord_Bots\venv\lib\site-packages\discord\voice_client.py", line 331, in connect
await self.disconnect(force=True)
File "C:\Users\vitek\OneDrive\Dokumenty\Pycharm Projects\Discord_Bots\venv\lib\site-packages\discord\voice_client.py", line 423, in disconnect
if self.ws:
AttributeError: 'VoiceClient' object has no attribute 'ws'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\vitek\OneDrive\Dokumenty\Pycharm Projects\Discord_Bots\venv\lib\site-packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\vitek\OneDrive\Dokumenty\Pycharm Projects\Discord_Bots\venv\lib\site-packages\discord\ext\commands\core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\vitek\OneDrive\Dokumenty\Pycharm Projects\Discord_Bots\venv\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'VoiceClient' object has no attribute 'ws'
你有一些提示如何解决这个问题吗?我真的会感谢一些支持非常感谢你。
解决方案
推荐阅读
- gremlin - AWS 海王星上的 gremlin 遍历
- node.js - App Engine Flex 启动实例的高延迟和延迟
- xpath - XMLExists 或 ExistsNode:在 FROM 子句中使用两个 XML 引用时在 WHERE 子句中使用
- javascript - 代码游戏:儿童游戏
- firebase - 从 Firestore 获取数据时调用 get() 函数需要多少“读取”
- swift - Swift for Windows 10 print() 命令不打印
- python - Unable to run python Flask decorator in blueprints
- c# - Unable to export RSA private parameters when running as administrator
- apache-spark - Spark 未使用所有可用的 CPU
- unity3d - HoloLens/Unity shared experience: How to track a user's "world" position instead of Unity's position?