[英]Is there a way to send a specific message to a specific server and channel on discord with python?
I just need to send a message that says "!daily" in a server called 'bot-commands' every 86401 seconds (24 hours and 1 second)我只需要每 86401 秒(24 小时零 1 秒)在名为“bot-commands”的服务器中发送一条消息,上面写着“!daily”
Any tips please请有任何提示
Assuming you want to do a command with another bot, most bots make it so other ones can't do commands, so it probably won't work, but you can make a before_loop
:假设您想对另一个机器人执行命令,大多数机器人都会这样做,因此其他机器人无法执行命令,因此它可能无法正常工作,但您可以创建一个
before_loop
:
import asyncio
import datetime as dt
@bot.event
async def on_ready():
print("Logged in as")
print(bot.user.name)
print("------")
msg1.start()
# Message 1
@tasks.loop(hours=24)
async def msg1():
message_channel = bot.get_channel(705524214270132367)
await message_channel.send("test 1")
@msg1.before_loop
async def before_msg1():
for _ in range(60*60*24): # loop the hole day
if dt.datetime.now().hour == 10+12: # 24 hour format
print('It is time')
return
await asyncio.sleep(1)# wait a second before looping again. You can make it more
Another option is using a workflow website such as IFTTT or Zapier.另一种选择是使用工作流网站,例如 IFTTT 或 Zapier。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.