Reputation: 173
I've been developing a discord bot for the past month, I've been doing commands using on_message listeners, which according to alot of people online isn't very ideal, so I decided to take it to the next step and do it properly, I looked at the documentation and came up with this basic code:
import discord #import all the necessary modules
from discord import Game
from discord.ext import commands
client = discord.Client() #define discord client
bot = commands.Bot(command_prefix='!') #define command decorator
@bot.command(pass_context=True) #define the first command and set prefix to '!'
async def testt(ctx):
await ctx.send('Hello!!')
@client.event #print that the bot is ready to make sure that it actually logged on
async def on_ready():
print('Logged in as:')
print(client.user.name)
await client.change_presence(game=Game(name="in rain ¬ !jhelp"))
client.run(TOKEN) #run the client using using my bot's token
Before going through the pain of implementing all of my commands to this new way of doing things, I wanted to test it so I know that it works for sure and sadly, it didn't, I went through a bunch of posts and documentation again but I couldn't spot what I did wrong, the bot logs in fine to the proper user and I just can't seem to figure out and understand what the problem is, I am probably missing something obvious yet again
Could anyone help, that would be great, thank you!
Upvotes: 3
Views: 17998
Reputation:
By saying client = discord.Client()
you make an discord client which will be online of course (If it isn't even online tell me) and you made an discord bot with bot = commands.Bot(command_prefix='!')
. The discord bot won't run, only the discord client will because you only did run the client with client.run(TOKEN)
. So a quick preview of what your code should be and would hopefully work:
import discord #import all the necessary modules
from discord import Game
from discord.ext import commands
bot = commands.Bot(command_prefix='!') #define command decorator
@bot.command(pass_context=True) #define the first command and set prefix to '!'
async def testt(ctx):
await ctx.send('Hello!!')
@bot.event #print that the bot is ready to make sure that it actually logged on
async def on_ready():
print('Logged in as:')
print(bot.user.name)
await bot.change_presence(game=Game(name="in rain ¬ !jhelp"))
bot.run(TOKEN) #run the client using using my bot's token
Upvotes: 8