Green to python, having issues with Discord Embed - python-3.x

So keep getting a Type error stating send() got an unexpected keyword argument 'Embed'
I'm not sure what I did wrong. Any help would be awesome.
client = discord.Client()
#client.event
async def on_message(message):
if message.content == 'what is the version':
dev_channel = client.get_channel(Deleted for obs reasons)
myEmbed = discord.Embed(title="Current Version", description="The bot
is in Version 1.0", color=0x00ff00)
myEmbed.add_field(name="Version Code:", value="v1.0.0", inline=False)
myEmbed.add_field(name="Date Released:", value="November 25th, 2020",
inline=False)
myEmbed.set_footer(text="End of message")
await dev_channel.send(Embed=myEmbed)
Visual Studios gives following text in terminal when I type what is the version in the discord text channel.
Ignoring exception in on_message
Traceback (most recent call last):
", line 333, in _run_event
File "C:\Users\lazy5\AppData\Local\Programs\Python\Python39\lib\site-
packages\discord\client.pyy", line 333, in _run_event
await coro(*args, **kwargs)
File "c:\Users\lazy5\Desktop\worth.py", line 30, in on_message
await dev_channel.send(Embed=myEmbed)
TypeError: send() got an unexpected keyword argument 'Embed'

On your send line
await dev_channel.send(Embed=myEmbed)
'Embed=' should be lowercase like so:
await dev_channel.send(embed=myEmbed)

Related

How to edit embed with message id discord bot py in on_ready event

I want to edit a embed in on_ready event this is the only way i can edit can do on_message or is there a way to keep a function running until the program ends?
from discord.ext import commands
import discord
from discord.utils import get
#bot.event
async def on_ready():
msg = bot.get_message(892788147287654471)
em = discord.Embed(title="lik",description="kjk")
await msg.edit(embed=em)
bot.run(os.environ['token'])
error code:
Ignoring exception in on_ready
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 56, in on_ready
msg = bot.get_message(892788147287654471)
AttributeError: 'Bot' object has no attribute 'get_message'
Well as the error says, bot has no get_message attribute. Instead what you can do is get the channel, and then get the message or partial message within.
https://discordpy.readthedocs.io/en/master/api.html?highlight=partial%20message#discord.PartialMessage
Example:
message = bot.get_channel(1234567890).get_partial_message(1234567890)
await message.edit(content="test")

I am trying to make a simple replying bot on discord with discord.py however I am getting this error and Im not sure why

The thing thats weird is that, I dont even have 343 lines of code, I only have like 30, so I'm really not sure why this is happening
The error :
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\aiosdj\PycharmProjects\nerdeyes\venv\lib\site-packages\discord\client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "C:/Users/aiosdj/PycharmProjects/nerdeyes/main.py", line 28, in on_message
await bot.send_message(message.channel, msg)
AttributeError: 'Bot' object has no attribute 'send_message'
The code :
import asyncio
from discord.ext import commands
bot = commands.Bot(command_prefix='.nerd ', description = 'nerd eyes')
#bot.event
async def on_ready():
guild_count = 0
for guild in bot.guilds:
print(f"- {guild.id} (name: {guild.name})")
guild_count = guild_count + 1
print('Nerdeyes has awoken in ' + str(guild_count) + " servers")
#bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith('.nerd'):
msg = 'eyes'.format(message)
await bot.send_message(message.channel, msg)
bot.run("TOKEN")
Bot.send_message doesn't exist, which is what your error also says. You need something that implements Messageable, like a Channel, User, or Member - and the method is called send, not send_message. A quick look at the API docs for Bot also shows that this method is nowhere to be found. It's generally not a bad idea to first check if a method exists before using it.
await message.channel.send(msg)
Also, msg = 'eyes'.format(message) - the .format here does nothing at all, this is the same as just 'eyes'.
I dont even have 343 lines of code
The error says it happens in \venv\lib\site-packages\discord\client.py line 343, not your file. This is a line in the Discord library, which your code calls, so at one point or another one of those methods will crash. The line below in the error says which line of yours it comes from (28).
ps. You just leaked your bot token, generate a new one.

Facing error when using buttons from discord components in cogs Discord.py

import discord
from discord.ext import commands
bot = discord.ext.commands.Bot(command_prefix = ";");
import random
from asyncio import TimeoutError
import subprocess
import sys
from discord_components import *
class GameCommands(commands.Cog):
def __init__(self, bot):
self.bot=bot
#commands.Cog.listener()
async def on_ready(self):
DiscordComponents(bot)
print('ready')
#commands.command()
async def rps(self,ctx):
choices=['rock','paper','scissors']
bot_choise=random.choice(choices)
player_choise=""
yet= discord.Embed(title=f"{ctx.author.display_name}'s Rock Paper Scissors Game", description="Click On A Button", color=discord.Color.from_rgb(0, 208, 255))
won= discord.Embed(title=f"You Won! Le Hurray!", description=f"You chose {player_choise} and the Bot chose {bot_choise}", color=discord.Color.from_rgb(255, 213, 0))
lost= discord.Embed(title=f"You Lost! Sadge :(", description=f"You chose {player_choise} and the Bot chose {bot_choise}", color=discord.Color.from_rgb(102, 61, 69))
tie= discord.Embed(title=f"Hmm, A tie!", description=f"You and the bot both chose {bot_choise}", color=discord.Color.from_rgb(137, 49, 181))
out= discord.Embed(title=f"Timeout ", description=f"You didn't choose any option in time, Bruh!", color=discord.Color.from_rgb(43, 194, 146))
m = await ctx.send(embed=yet,components=[[Button(style=1 ,label="Rock"),Button(style=3 ,label="Paper"),Button(style=4 ,label="Scissors")]])
def check(res):
return ctx.author==res.user and res.channel==ctx.channel
try:
res= await self.bot.wait_for("button_click", check=check, timeout=15)
player_choise= res.component.label
if player_choise==bot_choise:
await m.edit(embed=tie, components=[])
if player_choise=="Paper" and bot_choise=="Rock":
await m.edit(embed=won, components=[])
if player_choise=="Scissors" and bot_choise=="Paper":
await m.edit(embed=won, components=[])
if player_choise=="Rock" and bot_choise=="Scissors":
await m.edit(embed=won, components=[])
if player_choise=="Rock" and bot_choise=="Paper":
await m.edit(embed=lost, components=[])
if player_choise=="Paper" and bot_choise=="Scissor":
await m.edit(embed=lost, components=[])
if player_choise=="Scissor" and bot_choise=="Rock":
await m.edit(embed=lost, components=[])
except TimeoutError:
await m.edit(embed=out, components=[])
def setup(bot):
bot.add_cog(GameCommands(bot))
I have discord-components installed, whenever i run the command i get this error:
Ignoring exception in command rps:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "/home/runner/TheDuck/commands/games.py", line 37, in rps
m = await ctx.send(embed=yet,components=[[Button(style=1 ,label="Rock"),Button(style=3 ,label="Paper"),Button(style=4 ,label="Scissors")]])
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_components/client.py", line 46, in send_component_msg_prop
return await self.send_component_msg(ctxorchannel.channel, *args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_components/client.py", line 177, in send_component_msg
data = await self.bot.http.request(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 192, in request
async with self.__session.request(method, url, **kwargs) as r:
AttributeError: 'NoneType' object has no attribute 'request'
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 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, 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: 'NoneType' object has no attribute 'request'
I don't know what is causing this error. I tried finding about it online but couldn't.
I would Like to know what possible mistake i might be making or is it a bug.
I saw almost the same code being run on the main file without any problems. Is it a problem with cogs or my code is wrong?
While I am unsure if that is a bug or not, I think it would be better to use Discord.py 2.0 (Currently in Alpha) for buttons instead of third party libs. Keep in mind it might be unstable so is your choice.

Discord.py Python economy bot with mongodb "NoneType" error

(bad english)
I wanna create a economy bot with mongodb, it worked fine 2 days ago but now I have "NoneType" error
Sorce code from main.py(to add user in db):
#client.event
async def on_ready():
print(f'''
[*]BOT: ON
[*]BOT NAME : {client.user}
[*]BOT ID: {client.user.id}
''')
for guild in client.guilds:
for member in guild.members:
post = {
"_id": member.id,
"balance": 10000000,
"xp": 0,
"level": 1
}
if collection.count_documents({"_id": member.id}) == 0:
collection.insert_one(post)
That code is working because I see that on db
Source code from cog with problem:
class Economic(commands.Cog):
def __init__(self, client):
self.client = client
self.cluster = MongoClient(f"mongodb+srv://discord:{secret}#cluster403.xn9cm.mongodb.net/discord1?retryWrites=true&w=majority")
cluster = MongoClient(f"mongodb+srv://discord:{secret}#cluster403.xn9cm.mongodb.net/users?retryWrites=true&w=majority")
self.collection = cluster.users.tutu
#commands.command(
name = "balance",
aliases = ["ball","money"],
brief = "User balance",
usage = "balance <#user>",
description = "none....."
)
async def user_balace(self, ctx, member: discord.Member = None):
if member is None:
embed = discord.Embed(
title = f"__{ctx.author}__'s balance",
description = f"Money: {self.collection.find_one({'_id': ctx.author.id})['balance']}"
)
await ctx.send(embed=embed)
When I type ">balance" command in console I get that error:
Ignoring exception in command balance:
Traceback (most recent call last):
File "D:\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "C:\Users\Nick403\Desktop\Apps\PROJECTS\BOT\cogs\eco.py", line 22, in user_balace
description = f"Money: {self.collection.find_one({'_id': ctx.author.id})['balance']}"
TypeError: 'NoneType' object is not subscriptable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "D:\lib\site-packages\discord\ext\commands\bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "D:\lib\site-packages\discord\ext\commands\core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "D:\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: 'NoneType' object is not subscriptable
Can somebody help me ? (sorry for my bad english)
The error message is essentially saying that self.collection.find_one({'_id': ctx.author.id}) is returning as None. In the PyMongo Documentation, we can see that find_one() will return None when no such item is found in the collection. I would rewrite your code to have a safety in the event of not having a specific user in your database.
if self.collection.find({'_id': ctx.author.id}).count() == 0:
self.collection.insert_one({USER OBJECT})
user = self.collection.find_one({'_id': ctx.author.id})

Reaction on the message

My code
#bot.event
async def on_message(message):
emoji = '🎨'
message = message.id
await bot.add_reaction(message, emoji)
Error in console
Ignoring exception in on_message
Traceback (most recent call last):
File "/home/runner/.local/share/virtualenvs/python3/lib/python3.7/site-packages/discord/client.py", line 270, in _run_event
await coro(*args, **kwargs)
File "main.py", line 31, in on_message
AttributeError: 'Bot' object has no attribute 'add_reaction'
How to fix this error?
As the python interpreter helpfully points out, your Bot object doesn't have the function add_reaction(). Instead, it's available to the Message object:
#bot.event
async def on_message(message):
emoji = '🎨'
await message.add_reaction(emoji)
You can look at their FAQ for more help: "How do I add a reaction to a message?"

Resources