How to go bot online on Python - python

I'm having some difficulties getting the bot online. When I run the file the bot is not online on the server I need. Before I used pycharm but due to many errors on my computer, I migrated to VSCode. In pycharm it worked normally, but now in VSCode I can't make it work. Can someone help me?
The variables token and canal_id are correcty configured on my code and i already check on My applications on discord.
Code:
import asyncio
from datetime import datetime, timedelta
import discord
from discord.ext import commands
token = 'TOKEN'
canal_id = 0000
bot = commands.Bot(command_prefix='%')
#bot.event
async def on_ready():
print('Got online')
bot.run(token)

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)

Related

discord.client: logging in using static token help me

enter image description here
Code:
import discord
import os
import sys
import asyncio
import time
import json
from discord.ext import commands
from discord.utils import get
bot = commands.Bot(command_prefix='*', intents=discord.Intents.all())
TOKEN= 'ODU1MDAwMzU3Njk2NDM4MzEy.Gxtt2S.IxUbC9bS8Ps3hTeUYpwxW_U7A6q0MuzTwJxUFA'
#bot.event
async def on_ready():
print(" Bot account ")
print()
print(f"Username: {bot.user.name}")
print(f"Bot ID: {bot.user.id}")
print(f"Bot token: {TOKEN}")
print()
bot.run(TOKEN)
Your code is throwing an discord.errors.PrivilegedIntentsRequired Exception as you can see in the bottom line of your screenshot.
This means it is trying to use intents that it has no permission to use. Either enable those intents in the discord developer portal or replace discord.Intents.all() with the intents that you really need and have sufficient permissions for.

Discord.py: Commands don't work but events work, and no errors [duplicate]

This question already has an answer here:
Commands don't run in discord.py 2.0 - no errors, but run in discord.py 1.7.3
(1 answer)
Closed 10 months ago.
I've made a discord bot, but when I run it, events work fine, all the cogs load in correctly. But the commands wouldn't work, when I use a command, it wouldn't show the output.
I used discord.py on version 2.0.0
Here is the code:
import config
import discord
from discord.ext import commands
import random
import json
import os
client = commands.Bot(command_prefix=config.PREFIX)
client.remove_command('help')
#client.event
async def on_ready():
print('ONLINE')
#client.command()
async def ping(ctx):
#This is not a actual command I have but it wouldn't work anyway
print("Pong")
client.run(config.TOKEN)
As of Discord.py 2.0, you have to have message intents for normal commands to work properly.
In this example, there are selected default intents which include message_content intent.
import config
from discord import Intents
from discord.ext import commands
client = commands.Bot(command_prefix=config.PREFIX, intents=Intents.default(), help_command=None)
#client.event
async def on_ready():
print('ONLINE')
#client.command()
async def ping(ctx):
#This is not a actual command I have but it wouldn't work anyway
print("Pong")
client.run(config.TOKEN)

Discord bot python script

I am coding a discord bot for my special interest can I have some help, please? The code format is this:
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)```
How do I make this work?
I would suggest, that you defined client wrong. Try:
from discord.ext import commands
//*Your dotenv stuff here*
client = commands.Bot(command_prefix="Your prefix here")
client.run(TOKEN)
I hope it works, if not, feel free to correct me.

Discord Python Bot not sending responses to commands

We are creating an Discord bot.
The Problem is that no error is in Console but the Chat in Discord is also empty. So no response at all. Could you please help me and say what my error is and how to resolve the problem
Best Wishes,
Niktix
import discord
from discord.ext import commands
import asyncio
from dotenv import load_dotenv
from discord.ext.commands import Bot
import askai
import numpy
import random
import json
import datetime as DT
from time import sleep
import sLOUT as lout
import os
botStartTime = DT.datetime.now()
ver = ['v1.0.8', '2021-01-13']
config = 'config.yml'
bot = commands.Bot(command_prefix = '!')
lout.writeFile('AskAIBotLogs.txt', '\naskai initialisiert!', True)
load_dotenv()
#bot.command(pass_context=True)
async def time(ctx):
startTime = DT.datetime.now()
await ctx.send('Auf dem server ist aktuell folgende Uhrzeit: {}'.format(DT.datetime.now()))
lout.log(config, startTime, 'time')
#bot.event
async def on_ready():
await bot.change_presence(activity=discord.Activity(type=1, name='Beantwortet Fragen', url='https://www.youtube.com/watch?v=e3tuUKGIaGw', platform='YouTube', assets='askai',))
lout.log(config, botStartTime, None, None, True)
print('Eingeloggt als {}'.format(bot.user.name))
#bot.event
async def on_message(message):
if message.author.bot:
return
if message.channel.name != "askai-support":
return
if message.content.startswith("!"):
return
await bot.process_commands(message)
await message.channel.send(askai.ask(message.content))
bot.run('token')
Why does it not work? Well, the answer is fairly simple. Please refer to the following lines you provided:
#bot.event
async def on_message(message):
if message.author.bot:
return
if message.channel.name != "askai-support":
return
At this point in the code, you provide the channel name. Although, you don't provide the channel ID afterward. Therefore the bot cannot get said channel. In order to get the channel ID, please refer to Discord's official guide here. Upon doing that, make the same line of code as above, although replace "message.channel.name" with "message.channel.ID". Let me know if you have any further questions. Best Regards,

Can't run a discord.py script due to pylint error

I am newbie learning discord.py Rewrite. I just wrote a small code for making a discord bot online and run the ping command. At the the first time, it was working fine, then it started saying error in Visual Studio Code that its a pylint error which can't export the discord file. The error is unable to import 'discord' and 'discord.ext'
My code is like this:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = '_')
#client.event
async def on_ready():
print ('The Bot is ready')
#client.command()
async def ping(ctx):
await ctx.send (f'Pong!{(round(client.latency * 1000))}ms')
client.run('BOT_TOKEN')
You didnt import discord.py library:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = '_')
#client.event
async def on_ready():
print ('The Bot is ready')
#client.command()
async def ping(ctx):
await ctx.send (f'Pong!(round(client.latency*1000))ms')
client.run ('BOT_TOKEN')
If it won't help you, you should install it. https://packaging.python.org/tutorials/installing-packages/

Categories

Resources