errors with content discord.py - python

#client.command()
#commands.cooldown(1, 5, commands.BucketType.user)
async def say(ctx, *, response):
if "#" in say.content.contains:
await ctx.send("no")
else:
response = response.replace("(", "")
response = response.replace(")", "")
await ctx.send(response)
I'm trying to make it so if you type .say then anything with an # will cancel the command
error message: if "#" in say.content.contains:
AttributeError: 'Command' object has no attribute 'content'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 859, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Command' object has no attribute 'content'

Don't use say.content. The variable say isn't the message being typed, it's the function/name of the function.
Try using ctx.message.content instead of say.content

Related

Dictionary "Command' Object is not subscriptable

I am trying to make a bot that does a very simple task, it adds points to a member in the channel for the time the bot is live, in a temporary context. Trying to accomplish this without databases, because I don't need a permanent record of these points. I seem to have come very close to a solution combining a lot of references I've found over the internet. In essence, I create a dictionary based on the member ID and add 1 that key value pair whenever I use the give command, however, I keep getting the error listed below, I appreciate your time and please if someone can explain to me WHY this sub scriptable error happens with my code, Thank you and have a great day.
Adding my code below:
import discord
from discord.ext.commands import Bot
from collections import defaultdict
TOKEN = '#code would go here.'
bot = Bot('!')
points = defaultdict(int)
#bot.event
async def on_ready():
print('We have logged in as {0.user}'.format(bot))
#bot.event
async def on_message(message):
username = str(message.author).split('#')[0]
user_message = str(message.content)
channel = str(message.channel.name)
print(f'{username}: {user_message} ({channel})')
if message.content == "hello":
# SENDS A MESSAGE TO THE CHANNEL.
await message.channel.send("FIX CONTEXT")
# INCLUDES THE COMMANDS FOR THE BOT. WITHOUT THIS LINE, YOU CANNOT TRIGGER YOUR COMMANDS.
await bot.process_commands(message)
#bot.command(pass_context=True)
async def give(ctx, member: discord.Member):
points[member.id] += 1
ctx.send("{} now has {} radiation".format(member.mention, points[member.id]))
#bot.command(pass_context=True)
async def points(ctx, member: discord.Member):
ctx.send("{} has {} radiation".format(member.mention, points[member.id]))
bot.run(TOKEN)
The main thing I don't understand about my code is the line Command raised an exception: TypeError: 'Command' object is not subscriptable
We have logged in as RadiationTracker#7562
AdamKostandy: !!give AdamKostandy#9900 (ffg-game-chat)
Ignoring exception in command None:
discord.ext.commands.errors.CommandNotFound: Command "!give" is not found
AdamKostandy: !give AdamKostandy#9900 (ffg-game-chat)
Ignoring exception in command give:
Traceback (most recent call last):
File "C:\Users\Adam\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:/Users/Adam/Documents/GitHub/Discord-Bot/main.py", line 34, in give
points[member.id] += 1
TypeError: 'Command' object is not subscriptable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Adam\anaconda3\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Adam\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Adam\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'Command' object is not subscriptable
AdamKostandy: !points AdamKostandy#9900 (ffg-game-chat)
Ignoring exception in command points:
Traceback (most recent call last):
File "C:\Users\Adam\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:/Users/Adam/Documents/GitHub/Discord-Bot/main.py", line 39, in points
ctx.send("{} has {} radiation".format(member.mention, points[member.id]))
TypeError: 'Command' object is not subscriptable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Adam\anaconda3\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Adam\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Adam\anaconda3\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'Command' object is not subscriptable

Why do I get the error "send() got an unexpected keyword argument" when running a command with my selfbot?

I am trying to make a Selfbot in Python. I have this command to DM all users in a guild. In a guild I do {prefix}dmall (message) and then send it and get this error.
#knife.command() # dms all guild users
async def dmall(ctx):
for user in ctx.guild.members:
await user.send(message=ctx.message)
Ignoring exception in command dmall:
Traceback (most recent call last):
File "E:\python\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\me\OneDrive\Desktop\endless sb template\main.py", line 104, in dmall
await user.send(message=ctx.message)
TypeError: send() got an unexpected keyword argument 'message'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "E:\python\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "E:\python\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "E:\python\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: send() got an unexpected keyword argument 'message'
Remove the keyword message in the line await user.send(message=ctx.message)
I don't know what you're trying to do here but try this:-
#knife.command()
async def dmall(ctx):
for user in ctx.guild.members:
await user.send(ctx.message)

Command raised an exception: AttributeError: 'File' object has no attribute 'to_dict' for Discord bot

#bot.command()
async def catto(ctx):
choice = ["1","2"]
print(random.choice(choice))
if choice == 1:
r = requests.get("APILINK").json()
cat_embed = discord.Embed()
cat_embed.set_image(url=r["url"])
await ctx.send(embed=cat_embed)
else:
file = discord.File("FILEPATH")
file2 = discord.File("FILEPATH")
cats = (file, file2)
await ctx.send(embed = random.choice(cats))
It's in the else bit Im having problems where it gives me the error as said in the title.
Full Traceback as suggested:
Ignoring exception in command catto:
Traceback (most recent call last):
File "C:\Users\OneDrive\Documents\Programming-Extra\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\OneDrive\Documents\Programming-Extra\Discord Bot\BOTNAME", line 46, in catto
await ctx.send(embed = random.choice(cats))
File "C:\Users\OneDrive\Documents\Programming-Extra\lib\site-packages\discord\abc.py", line 1017, in send
embed = embed.to_dict()
AttributeError: 'File' object has no attribute 'to_dict'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\OneDrive\Documents\Programming-Extra\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\OneDrive\Documents\Programming-Extra\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\OneDrive\Documents\Programming-Extra\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'File' object has no attribute 'to_dict
Fix
The error is with the last line:
await ctx.send(embed = random.choice(cats))
It should be like this instead:
await ctx.send(embed=discord.Embed(file=random.choice(cats))
or like this:
await ctx.send(file=random.choice(cats))

Make the bot discord send a message when someone type "!clear" has no permission

#client.command(pass_context=True)
#commands.has_permissions(administrator=True)
async def clear(ctx,amount=1000):
await ctx.channel.purge(limit=amount)
#clear.error
async def clear_error(ctx,error):
if isinstance(error, MissingPermissions):
text = "Sorry {}, you do not have permissions to do that!".format(ctx.message.author)
await client.send_message(ctx.message.channel, text)
output: ( I want it to send a message to that user, who have no permission administration, and delete his message I dont understand this error, it happeen when I try to send please fix it ty would you fix it for me guys thank you im new here. )
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 855, in invoke
await self.prepare(ctx)
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 777, in prepare
if not await self.can_run(ctx):
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 1087, in can_run
return await discord.utils.async_all(predicate(ctx) for predicate in predicates)
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\utils.py", line 348, in async_all
for elem in gen:
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 1087, in <genexpr>
return await discord.utils.async_all(predicate(ctx) for predicate in predicates)
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 1790, in predicate
raise MissingPermissions(missing)
discord.ext.commands.errors.MissingPermissions: You are missing Administrator permission(s) to run this command.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 71, in wrapped
ret = await coro(*args, **kwargs)
File "c:\Users\cyberx\Desktop\Paid projects\Discord bot\bot.py", line 25, in clear_error
await client.send_message(ctx.message.channel, text)
AttributeError: 'Bot' object has no attribute 'send_message'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "c:\Users\cyberx\Desktop\Paid projects\Discord bot\bot.py", line 14, in on_message
await client.process_commands(message)
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 976, in process_commands
await self.invoke(ctx)
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\bot.py", line 943, in invoke
await ctx.command.dispatch_error(ctx, exc)
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 424, in dispatch_error await injected(ctx, error)
File "C:\Users\cyberx\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\ext\commands\core.py", line 77, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Bot' object has no attribute 'send_message'
You need to make an error handler, like this:
#<commandname>.error
async def <commandname>_error(self, ctx, error):
if isinstance(error, commands.MissingPermissions): #could be other type of error
await ctx.send(f"Sorry {ctx.author.mention}, you do not have permissions to do that!")
If you are a newcomer, I recommend reading this: https://vcokltfre.dev/tutorial/12-errors/
Also, to delete the trigger just use await ctx.message.delete()
Firstly, the error handler should be commands.MissingPermissions not MissingPermissions.
Secondly, client.send_message() was deprecated in the rewrite.
Thirdly, I don't think you can use discord.py in python 2.7, maybe upgrade to python 3.

Unresolved attribute reference 'voice_client_in' for class 'Bot'

I want to make a discord bot that can queue a song. I saw a code here but the code showed an error like this :
Traceback (most recent call last):
File "C:\Users\Komputer\PycharmProjects\CiaaBot\venv\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Komputer\PycharmProjects\CiaaBot\venv\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "C:\Users\Komputer\PycharmProjects\CiaaBot\venv\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Bot' object has no attribute 'is_voice_connected'
What should I do then?
is_voice_connected is outdated
You should use Guild.voice_client
#bot.command()
async def queue(ctx):
if ctx.guild.voice_client: # Its connected to voice
...

Categories