Reputation: 11
I want to make a python bot that sends a message to a specific discord channel every hour, I searched up online but I only got tutorials using discord bots. I want to send the message from my OWN account and not a discord bot, I am a newbie too so i cant understand too complex codes! Thanks!
Upvotes: 1
Views: 2251
Reputation: 1
This is a basic bot you could use to post every hour; as Taku mentioned Discord TOS would be violated using a userbot.
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")
In the #comments it's pretty self explanatory.
Upvotes: 0