Python 不和谐机器人(功能类似于学校铃声)
我的想法是制造一个不和谐机器人,它会像我们学校的钟声一样同时响起。 在一天的开始,我写信聊天!打电话让我开始安排上课时间,但没用 这是我的代码:Python 不和谐机器人(功能类似于学校铃声),python,pycharm,discord.py,Python,Pycharm,Discord.py,我的想法是制造一个不和谐机器人,它会像我们学校的钟声一样同时响起。 在一天的开始,我写信聊天!打电话让我开始安排上课时间,但没用 这是我的代码: import asyncio from discord.ext import commands from discord import FFmpegPCMAudio from discord.utils import get import datetime TOKEN = '####' client = commands.Bot(command_p
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'
以下是console的说明:
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'
你有解决这个问题的方法吗?
我将非常感谢您的支持,非常感谢