最近几天,我一直在纠缠不和谐的bot python重写。我注意到添加多个功能会导致其他功能停止工作。我添加了一个循环任务,该任务从随机的URL列表发送视频,最初我认为这可能会导致其他功能停止工作,但是注释掉仍然会导致问题。当您没有错误消息出现时,这很烦人。任何帮助将不胜感激!
import discord
from discord.ext import commands, tasks
import re
from random import randint
client = commands.Bot(command_prefix = "//")
@client.event
async def on_ready():
print("The bot is doing stuff.")
@client.event
async def on_message(message):
"""Deletes <specific> YT link"""
if <specific yt link> in message.content:
await message.delete()
print("video deleted")
@client.event
async def on_message(message):
"Sends a peeposalute whenever someone says 'goodnight'"
gn = re.compile('goodnight|good night|gn')
if gn.search(message.content.lower()):
await message.channel.send('<:peepoSalute:665687773407215637>')
print('peepo has saluted')
@client.event
async def on_message(message):
"""Checks the #new-uploads channel, reacts to any new messages and adds the video URL to the list"""
if message.channel.id == <channel id>:
with open('videos.txt', 'a') as f:
f.write(message.content + '\n')
print("New video added to list")
message.add_reaction('<:Wowee:592122719546638408>')
@tasks.loop(hours=24)
async def daily_video():
"""Sends a random video in #general daily"""
with open('videos.txt', 'r') as f:
videos = f.readlines()
target_general_id = <channel id>
general_id = client.get_channel(target_general_id)
await general_id.send(videos[randint(0, len(videos) - 1)])
print("Daily video sent")
@daily_video.before_loop
async def before():
await client.wait_until_ready()
print("Finished waiting")
daily_video.start()
client.run(<token>)