Trying to use ack and getingg ban from discord Why? - discord

Code:
import discord
token = 'mytoken'
client = discord.Client()
#client.event
async def on_ready():
print("Online!")
for guild in client.guilds:
print(guild)
await guild.ack()
client.run(token, bot=False)
I am Getting ban from discord every time i using this
The owner of this website (discordapp.com) has banned you temporarily from accessing this website.

Because you sends more than normal human requests-per-second.
You can try to fix it with await asyncio.sleep() but I suggest you just stop using selfbots.
Possible fix:
#client.event
async def on_ready():
print("Online!")
for guild in client.guilds:
print(guild)
await guild.ack()
await asyncio.sleep(10) # Sleep for 10 seconds

Related

Discord bot with Interactions.py | on_message not receiving messages from any channel. How to listen for messages?

My bot has fully functioning /slash commands and I would also like them to be text commands and add other functionality when users send messages in chat. However, I cannot seem to get the bot to listen for messages.
import interactions
# Create the bot
Bot = interactions.Client(
token = BotToken,
scope = ServerID
)
#Bot.event
async def on_message(message):
await HandleMessage(message)
return
Bot.start()
The code never enters the on_message method.
I had a working version with the discord.py module and they are very similar. I am not sure why it does not work with Interactions.py.
Working code with discord.py:
intents = discord.Intents.default()
intents.messages = True
intents.message_content = True
client = discord.Client(intents = intents)
#client.event
async def on_message(message):
await HandleMessage(message)
client.run(Token)

Why wont my discord bot recognise commands?

I'm trying to make a discord bot that will provide the current price of crypto currencies when a command (!price) is used, below is my code i have taken out my bots token for obvious reasons
import requests
from discord import Client, Intents
intents = Intents.default()
intents.members = True
client = Client(intents=intents)
#client.event
async def on_ready():
print(f'Logged in as {client.user}')
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!price'):
symbol = message.content[6:].upper()
url = f'https://api.coingecko.com/api/v3/simple/price?ids={symbol}&vs_currencies=usd'
print(f'Fetching price for symbol: {symbol}')
response = requests.get(url)
print(f'API response: {response.json()}')
print(f'response.status_code: {response.status_code}')
try:
price = response.json()[symbol]['usd']
await message.channel.send(f'The price of {symbol} is ${price}')
except KeyError:
print(f'Error: Symbol {symbol} not found')
await message.channel.send(f'Error: Symbol {symbol} not found')
client.run('TOKEN GOES HERE')
i have tried literally everything, Ive added so many debugging tools and I'm fairly certain that the problem lies with my bot picking up my commands in the discord server,

How can I have a trigger without my command prefix, like welcome and not $welcome?

So I wanted to make a feature on my discord bot and I wanted it to respond when users say welcome and say Welcome! back. But every time I try it only responds to $welcome. ($ is my prefix). What should I do?
client = commands.Bot(command_prefix = "$")
#client.command()
async def welcome(ctx, message):
if any(word in message for word in welcome):
await message.channel.send("Welcome!")
#client.event
async def on_message(message):
if "welcome" in message.content:
await message.channel.send('Welcome!')

Discord.py Ban all discord issue

I created a ban all discord command by using a few tutorials on stack overflow but the problem is the bot attempts to ban itself and prioritizes that first, making the bot completely not work, any suggestions? Here's my code:
async def ban(ctx):
guild = ctx.message.guild
for member in ctx.guild.members:
try:
await member.ban(reason="Banned")
print(f"Banned {member.display_name}!")
except:
print(f"Could not ban {member.display_name}")
async def ban(ctx):
guild = ctx.message.guild
for member in ctx.guild.members:
if member.id == bot.user.id:
continue
try:
await member.ban(reason="Banned")
print(f"Banned {member.display_name}!")
except:
print(f"Could not ban {member.display_name}")
This code makes the bot continue the loop if the member is itself

Discord.py bot react to user's next message after using a specific command

For example:
I use !react command and then after 1 min I send a message and then the bot reacts to the message with a specific emoji. Is it possible?
#commands.command()
#commands.cooldown(1, 600, commands.BucketType.user)
async def cookieme(self, ctx):
...somehow remembers to this name and next time the user say something it reacts to the msg with a cookie
I don't really understand your question but I will try to help you:
#bot.command()
async def react(ctx):
def check(message):
return ctx.author == message.author and ctx.channel == message.channel
react = await bot.wait_for("message", check=check)
await react.add_reaction("🍪")

Resources