EOL while scanning string literal, Unknown Emoji - discord

Command raised an exception: HTTP Exception: 400 Bad Request (error code: 10014): Unknown Emoji and EOL while scanning string literal are the 2 errors I have having while trying to add a reaction to an embed msg with python (discord.py)
Here is the full code, the problem is around the exclamation mark
#client.command()
async def ask(ctx, *, question=None):
try:
page = urllib.request.urlopen(f'http://askdiscord.netlify.app/b/{ctx.message.author.id}.txt')
if page.read():
embed = discord.Embed(color=0xFF5555, title="Error", description="You are banned from using AskDiscord!")
await ctx.send(embed=embed, content=None)
return
except urllib.error.HTTPError:
pass
if question:
channel = client.get_channel(780111762418565121)
embed = discord.Embed(color=0x7289DA, title=question, description=f"""
Question asked by {ctx.message.author} ({ctx.message.author.id}). If you think this question violates our rules, click ❗️ below this message to report it
""")
embed.set_footer(text=f"{ctx.message.author.id}")
message = await channel.send(content=None, embed=embed)
for emoji in ('❗️'):
await message.add_reaction(emoji)
for emoji in ('🗑'):
await message.add_reaction(emoji)
embed = discord.Embed(color=0x55FF55, title="Question asked", description="Your question has been send! You can view in the answer channel in the [AskDiscord server](https://discord.gg/KwUmPHKmwq)")
await ctx.send(content=None, embed=embed)
else:
embed = discord.Embed(title="Error", description=f"Please make sure you ask a question...", color=0xFF5555)
await ctx.send(content=None, embed=embed)

Tuple need to have a , at the end if there is only one element in it else its considered as a string in your case change ('❗️') to ('❗️',)

Related

Discordpy Mod Logs Command

I'm trying to make a mod logs, I'm not really good at this, I scripted myself and kinda worked but it didn't worked. So basically my plan is when someone types .modlogs #channel, bot is gonna get the channel id and type it to json file with guild id, i made that it works very well I'm stuck on getting key info from json file, im printing the values and they are same.
#commands.command(aliases=['purge'])
#commands.guild_only()
#commands.has_permissions(manage_messages=True)
async def clear(self,ctx, arg: int = None):
if arg is None:
await ctx.send(':x: You need to state a value!')
else:
with open('./logs.json', 'r') as f:
logsf = json.load(f)
if ctx.guild.id in logsf:
embedv = discord.Embed(color = discord.Colour.random())
embedv.add_field(name='Event Type:', value="Clear")
embedv.add_field(name='Channel:', value= ctx.channel)
embedv.add_field(name='Moderator:', value=ctx.message.author)
embedv.footer(text='Epifiz Logging')
schannel = commands.get_channel(logsf[ctx.guild.id])
await ctx.channel.purge(limit=arg)
await discord.schannel.send(embed=embedv)
await ctx.send('Done')
elif ctx.guild.id not in logsf:
await ctx.channel.purge(limit=arg)
await ctx.send(':white_check_mark: Successfully cleared {} messages.'.format(arg))
also my json file:
{
"838355243817369620": 853297044922564608
}
Also guild id is on json file, its not wrong.
Output
You made multiple mistakes in your code. The reason why you are getting the error is because this line here if ctx.guild.id in logsf: returns False even if the guild's id is in your JSON file. Here is why:
logsf = json.load(f) returns a dictionary. You'll get {"838355243817369620": 853297044922564608} it's unclear whether 838355243817369620 or 853297044922564608 is your guild id but think of it this way:
s = {1:2}
2 in s return False
and the second mistake is inserting "838355243817369620" as a str rather than an int like this 838355243817369620.
The solution is to use list() as follow if ctx.guild.id in list(logsf): and to insert "838355243817369620" as an int in your JSON file so it looks like this:
{
838355243817369620: 853297044922564608
}
#rather than this
{
"838355243817369620": 853297044922564608
}
value in embeds accepts str not discord objects. Use f"{input}" rather than the object as an input.
embedv.add_field(name='Channel:', value= f"{ctx.channel}")
embedv.add_field(name='Moderator:', value=f"{ctx.message.author}")
await schannel.send(embed=embedv) rather than await discord.schannel.send(embed=embedv)
From this line schannel = commands.get_channel(logsf[ctx.guild.id]) I can assume that 838355243817369620 is your server's id. So, I think that you can use:
if ctx.guild.id in logsf.keys(): instead of if ctx.guild.id in list(logsf):
and make sure to convert its keys values into int rather than str to make it work.

Why does my discord bot not send a variable?

I have a bot that needs to send a message with a set message, followed by an integer defined by a variable. When I run this, the bot reacts to the message correctly but then doesn't send any response whatsoever. Why? XD (and yes I'm kinda bad and new at coding but idc I am determined to get this to work!)
EDIT: Ok it's sending the text and variable now, but it always prints as 0. Anyone know why it's always zero?
else:
emoji = '\N{Cross Mark}'
await message.add_reaction(emoji)
await message.channel.send("You messed it up at:")
await message.channel.send(f'{bowl_count}')
bowl_count == int(0)
Are you using on_message?
Also are you checking if bowl_count is equal to 0?
You don't need to provide int() unless you have a variable called 0 that's value is a string (text in quote marks)
else:
emoji = '\N{Cross Mark}'
await message.add_reaction(emoji)
await message.channel.send("YOU MESSED IT UP AT: ", bowl_count)
bowl_count = 0
Other than that it looks fine.
If you are using commands, then do define an await ctx.send("TEXT") as a variable called message
else:
emoji = '\n{Cross Mark}'
await message.add_reaction(emoji)
await message.channel.send("YOU MESSED IT UP AT: " + bowl_count)
bowl_count == int(0)
first, the escaped \N doesn't work, try \n
second, just use + to concatenate the strings
As a starter, you can not add a reaction that way, I would recommend doing this;
await message.add_reaction('👍')
As for using a valuable, you can do it using a f string:
text = "Hello!"
await ctx.send(f'{text}')

Discord.py bot recognising own messages even when it is told not to

I was trying to make a bot that if a message had certain keywords in it, it would say "why would you say",themessage,"?" but it recognises it's own messages so i tried to fix that but it still does. Here is my code:
import discord
from discord import user
client = discord.Client()
keywords = ["help", "william", "William", "Monkey", "monkey", "Monkaee", "monkaee", "monkae","Monkae"]
#client.event
async def on_message(message):
for i in range(len(keywords)):
if keywords[i] in message.content:
message2 = "Why would you say", message.content, "?"
if message.author.id == "750809710739062804":
await message.channel.send("shut it botty", delete_after=5)
else:
await message.channel.send(message2, delete_after=5)
then my token but i'm not gonna put that in. the id is the bot's id so it shouldnt recognise its own message but it does
You are comparing an Integer to a String
if message.author.id == "750809710739062804":
Try it without the quotes, like this:
if message.author.id == 750809710739062804:
Also, if you're trying to concatenate strings you should use
message2 = "Why would you say" + message.content + "?"
Instead of
message2 = "Why would you say", message.content, "?"

Bot saying only one word in string

As in title. I'm trying to get my bot to send an announcement, without having to use "" to capture the whole sentence. What the hell do you mean?
Here's my code:
#bot.command(pass_context=True)
#discord.ext.commands.has_permissions(administrator=True)
async def announce(ctx, message : str):
if message == None:
return
else:
embed = discord.Embed(title='yBot | ANNOUNCEMENT', description='', color= 0xFF0000)
embed.add_field(name="ANNOUNCEMENT: ", value="{}".format(message))
embed.set_footer(text="© 2020 - Powered by yanuu ;k#2137")
await ctx.send("||#everyone||")
await ctx.send(embed=embed)
Your issue is in the way you defined the command it self. It should be with a * so that it will take everything after
async def announce(ctx,*, message : str):
Have a look at this doc

Using Discord.py rewrite to delete messages

As the title states, I'm trying to delete messages using my !purge command. I have this down already:
#bot.command()
#commands.has_permissions(manage_messages=True)
async def purge(ctx):
await delete_messages(ctx, member)
await ctx.send("Deleted messages")
It's saying that delete_messages is not defined. Please help me!
So we are in year 2019. I'll help you with your code.
delete_messages is a method of a TextChannel object.
In your line await delete_messages(ctx, member), add ctx.message.channel. just before delete_messages.
Your line would then go like this:
await ctx.message.channel.delete_messages(ctx, member)
Hope that clears things up.
If it did, don't hesitate to 'accept' the answer by clicking the check mark.
This will delete only up to 99 messages (+ the purge command) at a time and the messages must be under 14 days old.
#bot.command(pass_context=True, name='purge', aliases=['purgemessages'], no_pm=True)
async def purge(ctx, number):
number = int(number)
if number > 99 or number < 1:
await ctx.send("I can only delete messages within a range of 1 - 99", delete_after=10)
else:
author = ctx.message.author
authorID = author.id
mgs = []
number = int(number)
channel = ctx.message.channel
async for x in bot.logs_from((channel), limit = int(number+1)):
mgs.append(x)
await delete_messages(mgs)
await ctx.send('Success!', delete_after=4)

Resources