python-3.x - Discord.py 重写:函数突然停止工作
问题描述
在过去的几天里,我一直在搞乱 discord bot python rewrite。我注意到添加多个功能往往会导致其他功能停止工作。我添加了一个循环任务,它从随机的 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>)
解决方案
推荐阅读
- excel - 用于检查日期和时间重叠的 Excel 公式
- flutter - 我是 Flutter 的绝对初学者,如何实现这种布局?
- reactjs - 努力在没有 web-pack 的现有 React 项目中安装 SCSS
- flutter - 它在声明变量性别时出错(颤振)
- kubernetes - 如何移除 Kubernetes 中卡住的 statefullset.apps?
- javascript - AWS Cognito adminCreateUser 导致 InvalidSignatureException
- matlab - MATLAB - 计算两个分布的重叠面积f
- visual-studio-code - 在 vscode 中生成 matplotlib 图表不起作用
- javascript - 如何根据位置选择元素?
- haskell - 尽管在编译器引用的值上使用了 realToFrac,但在输出 Int 时出现类型错误