discord.client: logging in using static token help me - python

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.

Related

how do I change discord bot presence in interactions,py

I'm creating my discord bot with the interactions.py library and I've com across a problem.
I can't seem to set my bots presence:
import interactions
import os
from keep_alive import keep_alive
bot = interactions.Client(token=os.getenv('TOKEN'), command_prefix="!f")
#bot.event
async def on_start():
activity = interactions.ClientPresence(
name="zkus /mravenci",
type=0,
)
await bot.change_presence(
activity=interactions.PresenceActivityType.GAME(activity))

on_message not being triggered when using interactions.Client

I'm using Interactions.py (client = interactions.Client) so that I can use its sophisticated slash commands system, but as a result the on_message event method is no longer triggered. When I use Discord.py (client = discord.Client) the on_message method works successfully.
How do I get on_message to work while using the slash command system of Interactions.py?
import os
import os.path
import interactions
import mysql.connector
import ast
from asyncio.windows_events import NULL
import operator as op
import discord
import inspect
from math import sqrt
from dotenv import load_dotenv
intents = discord.Intents
intents.messages = True
client = interactions.Client(token=TOKEN)
#client.command(
#command details here
)
async def count(ctx: interactions.CommandContext, command: str):
#manage incoming commands
#this only works correctly when I use client = interactions.Client
#client.event
async def on_message(message):
#do things based on message contents
#this only works correctly when I use client = discord.Client
client.Start()
Thanks!
It would be on_message_create, as this is the name that the discord api uses

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.py Import commands from another py

im trying to Import commands from another PY file. But it always Says command not exists...
This is my code in the file named test.py
from discord import Embed
from random import choice
from colorama import *
from os import path
from plyer import notification
intents = discord.Intents().all()
client = commands.Bot(command_prefix = ">", intents=intents)
#commands.command()
async def haha(ctx):
await ctx.send("hi")
import customcmd
client.run("censored")
The code in customcmd.py is
import discord
from discord.ext import commands, tasks
#commands.command()
async def hi(ctx):
await ctx.send(hi)#
Try this
from .customcmd import *

How to go bot online on 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)

Categories

Resources