[英]How do I make a bot to message every hour on discord without using a discord bot?
我想制作一个 python 机器人,它每小时向特定的不和谐频道发送一条消息,我在网上搜索过,但我只得到了使用不和谐机器人的教程。 我想从我的 OWN 帐户而不是不和谐的机器人发送消息,我也是新手,所以我无法理解太复杂的代码! 谢谢!
这是一个基本的机器人,您可以使用它每小时发布一次; 正如 Taku 提到的那样,使用用户机器人会违反 Discord TOS。
import random
import discord
from discord.ext import tasks
# Init the discord client
discord_client = discord.Client()
# The channel ID you want the bot to send your message to (Right click channel -> Copy ID)
channel_id = 000077777777770000
# Set the channel object using our channel ID number
channel = discord_client.get_channel(channel_id)
# List we will use these in the example to send random messages to the server
messages = [ "Hi I'm a bot!", "I'm just talking so you don't think I'm inactive!", "Blah blah blah blah blah!", "Add however many you like me to say in here!" ]
# Single message to get sent to the server string
single_message = "This will send over and over if multi_message = False."
# We will use this boolean to determine if we are just sending message string or a random one from messages list
multi_message = False
# Create a loop task for every 60 minutes [1 hour]
@tasks.loop(minutes = 60)
async def send_message():
# Call channel so we can modify it's value
global channel
# Make sure channel isn't null
if channel == None:
channel = discord_client.get_channel(channel_id)
# Wait for the discord bot to load before we start posting
await discord_client.wait_until_ready()
# Check to see if we are going to be sending different messages every hour or not
if multi_message:
# Print to output
print("Posted random message.")
# Send message to Discord channel
await channel.send(f"{random.choice(messages)}")
else:
print("Posted single message")
await channel.send(f"{single_message}")
# On bot ready
@discord_client.event
async def on_ready():
# Check to see if we are going to be sending different messages every hour or not
if multi_message:
print("* Sending random messages to the channel...")
else:
print("* Sending single message to the channel...")
# Start the message sending loop
send_message.start()
# Finished setting up
print("Bot ready.")
# Launch the Discord bot
print("+ Loading Discord message posting bot...")
discord_client.run("GET YOUR DISCORD TOKEN FROM DISCORD DEVELOPER PORTAL")
在#comments 中,这是非常不言自明的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.