add role by clicking on a link discord.py - python

I'm currently developing a discord bot that grabs the user IP, with their permission.
For that I would like that once they clicked on the link I'd display on the embed that the bot has given them the verified role.
I'm facing some issues with this.
My code:
import discord
from discord.ext import commands
import requests
from requests import get
from bs4 import BeautifulSoup
import os
import socket
import asyncio
bot = commands.Bot(command_prefix = "!", case_insensitive = True)
BOT_TOKEN = "my_token"
#bot.event
async def on_ready():
print('Connected to bot: {}'.format(bot.user.name))
print('Bot ID: {}'.format(bot.user.id))
print('''
██████╗░░░█████╗░████████╗███████╗░
██╔══██╗░██╔══██╗╚══██╔══╝██╔════╝░ 
██████╦╝░██║░░██║░░░██║░░░█████╗░░░ 
██╔══██╗░██║░░██║░░░██║░░░██╔══╝░░░
██████╦╝░╚█████╔╝░░░██║░░░███████╗░
╚═════╝░░░╚════╝░░░░╚═╝░░░╚══════╝░
''')
print('\nConnected to bot: {}'.format(bot.user.name))
print('Bot ID: {}'.format(bot.user.id))
await bot.change_presence(activity=discord.Game(name="Grabbing your stuff"))
#bot.command()
async def verify(ctx):
nome=ctx.author.name
embed = discord.Embed(
title=nome,
description = ':flag_pt:Clica [aqui]("site") para te verificares\n :flag_us:Click [here]("site") to verify',
colour = discord.Colour.green()
)
botmsg = await ctx.send(embed = embed)
await botmsg.add_reaction("✅")
bot.run(BOT_TOKEN)

Related

Discord bot message "application not responding"

I have a problem in my code.
this is my admin code :
import discord
class Admin(discord.Cog):
def __init__(self, bot):
self.bot = bot
self._last_member = None
#discord.command(name='clear', description='Permet de purger les messages du chat textuel.')
async def clear(self, ctx:discord.ApplicationContext, amount):
await ctx.channel.purge(limit=int(amount))
if __name__ == "__main__":
import main
this is my main code :
# Import discord libs
import discord
from discord.ext import commands
# Import addon libs
import random
import asyncio
# Import extra libs
from libs import settings
# Import Cogs
import admin
client = commands.Bot(command_prefix=" ", help_command=None, intents=discord.Intents.default())
client.add_cog(admin.Admin(client))
#client.event
async def on_ready():
print(f"logged in as {client.user}")
print("Bot is ready!")
await client.change_presence(status=discord.Status.online)
async def changepresence():
await client.wait_until_ready()
statuses = settings.BotStatus
while not client.is_closed():
status = random.choice(statuses)
await client.change_presence(activity=discord.Game(name=status))
await asyncio.sleep(10)
client.loop.create_task(changepresence())
client.run(settings.TOKEN)
this is my console in Visual studio code :
when i use my command /clear amount: he result this error :
but the command /clear amount: working perfectly :D
Can you help me to fix this please :D ?
You need to have the bot respond to the interaction: interaction.response.send_message("message")

My selfbot only responded to me and not other users

I run the code and send "xd", selfbot replies "lmao", but if another user writes "xd", selfbot does not reply "lmao", What do I do to make it respond to any user or bot?
import discord
from discord.ext.commands import Bot
from discord.ext import commands
import asyncio
#TOKEN
TOKEN = "u token"
client = discord.Client()
b = Bot(command_prefix = "x")
#b.event
async def on_ready():
print("I ready")
#b.event
async def on_message(message):
if message.content == "xd":
await message.channel.send("lmao")
b.run(TOKEN, bot = False)
you cant do on_message for commands anymore so i recomand you do something like this
#b.command()
async def xd(ctx):
await ctx.send("lmao")
self botting is agaist discord TOS

Not recognizing commands in discord with Python

I run this, it connects however when running it will not return anything when it comes to commands. I've tried changing this to the context return method from on every message. Previously only one message would appear, now none with this method even though both commands are the same with slight differences. What is my error on this? Sorry this is literally my first attempt at a discord bot.
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
botToken = os.getenv("DiscBotToken")
discClient = discord.Client()
bot = commands.Bot(command_prefix = "!")
#discClient.event
async def on_ready():
print(f"{discClient.user} is now connected.")
print('Servers connected to:')
for guild in discClient.guilds:
print(guild.name)
#bot.command(name = "about")
async def aboutMSG(ctx):
aboutResp = "msg"
await ctx.send(aboutResp)
#bot.command(name = "test")
async def testMSG(ctx):
testResp = "msg"
await ctx.send(testResp)
discClient.run(botToken)
You heading in the right direction commands.Bot have both event and command no need to use a client just for events.
You should either use discord.Client or commands.Bot not both in your case it is commands.Bot.
Also you are running the client only
import os
import discord
from discord.ext import commands
from dotenv import load_dotenv
load_dotenv()
botToken = os.getenv("DiscBotToken")
bot = commands.Bot(command_prefix = "!")
#bot.event
async def on_ready():
print(f"{discClient.user} is now connected.")
print('Servers connected to:')
for guild in discClient.guilds:
print(guild.name)
#bot.command(name = "about")
async def aboutMSG(ctx):
aboutResp = "msg"
await ctx.send(aboutResp)
#bot.command(name = "test")
async def testMSG(ctx):
testResp = "msg"
await ctx.send(testResp)
bot.run(botToken)

discord.ext.commands.errors.CommandNotFound: Command "play" is not found error

I'm trying to create a music bot for discord and I finish the code and tried to run it and when I run the play command it simply says this.
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "play" is not found
Here's my code.
import discord
from discord.ext import commands
import youtube_dl
TOKEN = "Token here"
bot = discord.ext.commands.Bot(command_prefix = "s ");
#bot.event
async def on_ready():
channel = discord.utils.get(bot.get_all_channels(), id=794444804607574026)
await channel.connect()
async def play(ctx, url):
player = await voice_client.create_ytdl_player(url)
player.start()
bot.run(TOKEN)
You haven't added #bot.command(name="play") above the play function
import discord
from discord.ext import commands
import youtube_dl
TOKEN = "Token here"
bot = discord.ext.commands.Bot(command_prefix = "s ");
#bot.event
async def on_ready():
channel = discord.utils.get(bot.get_all_channels(), id=794444804607574026)
await channel.connect()
#bot.command(name="play")
async def play(ctx, url):
player = await voice_client.create_ytdl_player(url)
player.start()
bot.run(TOKEN)
before
async def play(ctx, url):
player = await voice_client.create_ytdl_player(url)
player.start()
after
#bot.command()
async def play(ctx, url):
player = await voice_client.create_ytdl_player(url)
player.start()
Simply use this code:
main.py
from discord.ext import commands
from discord.ext.commands import bot
import discord
import os
import youtube_dl
bot = commands.Bot(command_prefix="s")
#bot.event
async def on_ready()
print("{0.user} is online".format(bot))
#bot.command()
async def play(ctx, url):
player = await voice_client.create_ytdl_player(url)
player.start()
.env
TOKEN=<paste your token here>
Hope it’s helped you (:

Python discord bots

I am currently trying to create my discord bot. sadly, this does not work and I have no Idea why...
import discord
import os
import time
from ka import keep_alive
from discord.ext import commands
import asyncio
client = commands.Bot(command_prefix = '.')
prefix = '.'
#client.event
async def on_ready():
print("I'm ready! {0.user}".format(client))
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="Croissants!"))
#client.command()
async def join(ctx):
channel = ctx.message.author.voice.voice_channel
await client.join_voice_channel(channel)
await ctx.send("On my way!")
client.run(os.getenv('TOKEN'))
there are NO errors. But no output aswell. I try making it join my vc by writing: .join
channel returns None, because ctx.message.author don't have voice attribute. Also, Client.join_voice_channel is deprecated since v1.0 (read here)
Instead of that, try this:
import discord
import os
import time
from ka import keep_alive
from discord.ext import commands
import asyncio
client = commands.Bot(command_prefix = '.')
prefix = '.'
#client.event
async def on_ready():
print("I'm ready! {0.user}".format(client))
await client.change_presence(activity=discord.Activity(type=discord.ActivityType.watching, name="Croissants!"))
#client.command()
async def join(ctx):
channel = ctx.guild.get_member(ctx.author.id).voice.channel # This
await channel.connect()
await ctx.send("On my way!")
client.run(os.getenv('TOKEN'))
Do client.add_command(join). You currently have the function for your command, but you haven't told the bot to recognize it as a command.

Categories

Resources