Skip to content

Instantly share code, notes, and snippets.

@ntdkhiem
Created March 5, 2019 00:53
Show Gist options
  • Save ntdkhiem/dd0a33d457509fc66158d5ff154f4c15 to your computer and use it in GitHub Desktop.
Save ntdkhiem/dd0a33d457509fc66158d5ff154f4c15 to your computer and use it in GitHub Desktop.
Run discord bot as a user
# A small program that send "!work" continuously in the discord's chat every 10 seconds as a user!
# # NOTE:
# - Make sure to use correct channel's id and user's id
# - Only works for python 3.x
# - Make sure to install all packages below via python's package manager
#
import discord
import asyncio
client = discord.Client()
DISCORD_CHANNEL_ID = 'CHANNEL_ID_HERE'
USER_ID = 'USER_ID_HERE'
START_COMMAND = '!start'
STOP_COMMAND = '!stop'
EXEC_COMMAND = '!work'
DELAY_TIME = 10
@client.event
async def on_message(message):
await client.wait_until_ready()
channel = discord.Object(id=DISCORD_CHANNEL_ID)
run = True
if message.content.startswith(START_COMMAND):
run = True
elif message.content.startswith(STOP_COMMAND) :
run = False
while run:
if run:
await client.send_message(channel, EXEC_COMMAND)
await asyncio.sleep(DELAY_TIME) # task runs every 10 seconds
else:
await client.send_message(channel, "Bot stop!")
return
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run(USER_ID ,bot=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment