I'm using Visual Studio Code for my bot. I just started and I can't get my bot to come online. This is my code
from discord.ext import commands
client = commands.Bot(command_prefix = '-')
#client.event
async def on_ready():
print('YEEEEEEEEET')
client.run('BOT_TOKEN')
I'm following tutorial from https://www.youtube.com/watch?v=nW8c7vT6Hl4
You need to create a bot and generate a token following: https://discordpy.readthedocs.io/en/latest/discord.html
It was a certificate problem, and not problem with the code.
Related
I am trying to build a Discord bot; which tells you about the weather condition. But no matter what I did I was unable to execute even the simplest commands such as:
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix="!")
#bot.command()
async def test(ctx, arg):
await ctx.send(arg)
client = discord.Client()
client.run(token)
I just do not get it on Discord side I enter the command "!test hello" to the chat screen and nothing happens. Please help thanks !
The problem is, that you first define a bot using bot = commands.Bot(command_prefix="!") then add the command to the bot, but then create a new client using client = discord.Client() and then run the client.
The problem here is that, you never run the bot, which has the command, so instead of
client = discord.Client()
client.run(token)
use
bot.run(token)
I've been using the
import os
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = "!")
#client.event
async def on_ready():
await client.change_presence(status=discord.Status.idle,
activity=discord.Game(''))
print('Successfully logged in as {0.user}'.format(client))
#client.command()
async def hello(ctx):
await ctx.send("Hello! It's great to see you!")
client.run(os.getenv('TOKEN'))
code for commands. I expected to have it respond "Hello! It's great to see you!" when I said !hello (! = prefix). But it returned nothing. Not even an error. Does anyone know why? Also, please don't show discord bot not responding to commands or Discord command bot doesn't responde (python) because I tried both, and neither worked.
I cant chat here because of lack of reputation so I answer it here instead. you should post the full code to make the job easier.
.
Cause 1:
You didn't add a prefix. You need a prefix to use the command
look onto your client. Did you tell the prefix already? like:
client = commands.Bot(command_prefix = "-")
if so, add this and it should work!
.
Cause 2:
You didn't import from discord.ext import commands
this is important if you want to use commands, import that and it should work!
.
Cause 3:
You mixing up client and bot
this might not happen but here it goes, You might mix up client or bot on the decorator, which is #client.command
if you use client (like client = commands.Bot(command_prefix = "-")), use #client.command on the decorator, while if you use Bot (bot = commmands.Bot(command_prefix = "-")) then you should use #bot.command on the decorator.
Hope these will help :D
So, when i was trying to add a status to my discord python bot, it wouldn't show up on discord, when running the code no errors would show up, it's just that the status wouldn't show itself.
#Connection to discord
#client.event
async def on_ready():
print({client.user}, 'has connected to Discord!')
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='~help'))
If anyone knows a fix to this please help.
import discord
import os
import config
import sys
client = discord.Client()
#client.event
async def on_ready():
print({client.user}, 'has connected to Discord!')
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name='~help'))
client.run(config.token) #imports token from the config.py
I tried your code in my test bot and it was working totally fine. I have attached the screenshots below and the code above. Not sure why it wouldn't work for you. [This is my entire code and has nothing extra attached in between or at the end].
Note: import config has my token (so it isn't a necessary import)
Okay so I wanted to make a discord bot for my first python project. However, despite my seemingly correct code, the bot doesn't run:
I used this basic code to simply get the bot online but nothing happens. I haven't seen anyone else have this problem either.
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = '.')
#client.event
async def on_ready():
print("Bot is ready")
client.run("Token") # i removed the token for security
and this is the result of the program
Am I doing something wrong?
I am using this version of the discord botting API: https://github.com/Rapptz/discord.py
As #jwjhdev said, client.run is not supposed to be tabbed under on_ready. If you delete the tab, then everything should work perfectly.
I'm trying to make a discord bot with discord.py for my discord server, I have extremely basic code that should get the bot online but instead just opens and then crashes.
import discord
#client.event
asnyc def on_ready():
print 'bot read`enter code here`y'
client.run('xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx')
I do have the token normally I just didn't want to leak. I appreciate all the help.
I found a nice tutorial to create a discord bot in python. Therefore you can create a connection with the following code:
import os
import discord
from dotenv import load_dotenv
load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
client = discord.Client()
#client.event
async def on_ready():
print(f'{client.user} has connected to Discord!')
client.run(TOKEN)
And I would suggest to rename the file from 'discord' to 'bot' or something else, so there are no conflicts with the import.