8ball embed command fails to launch - discord.py

I am trying to re-do my bot's 8ball command, I try to use the following code
#client.command(aliases=['8ball'])
async def _8ball(ctx, *, question):
responses = ['It is certain.',
'It is decidedly so.',
'Without a doubt.',
'Yes - definitely.',
'You may rely on it.',
'As I see it, yes.',
'Most likely.',
'Outlook good.',
'Yes.',
'Signs point to yes.',
'Reply hazy, try again.',
'Ask again later.',
'No.',
'Better not tell you now.',
'Cannot predict now.',
'Concentrate and ask again.',
"Don't count on it.",
'My reply is no.',
'My sources say no.',
'Outlook not so good.',
'Very doubtful.']
responses = random.choice(responses)
embed=discord.Embed(title="8ball", description="Ask the 8ball!", color=discord.Color.dark_purple())
embed.add_field(name="Q: {question}", value="A: {responses}", inline=False)
await ctx.send(embed=embed)
But the python file refuses to launch, and returns
File "C:\Users\r00t_technologies\Documents\bot\enigmatic-peak-21114\bot_development.py", line 135
await ctx.send(embed=embed)
^
SyntaxError: 'await' outside function
Is anyone able to help me with this issue?
EDIT: Nevermind I'm just an idiot and was looking at the wrong line, sorry for the inconvienience (I am somewhat inexperienced at this)

I Dont know Why the error say await outside a function but its already in function, i Edited Your Code And i Tested it in my Bot And it works perfectly.
So Try this:
#client.command()
async def _8ball(ctx, *, question):
responses = ['It is certain.',
'It is decidedly so.',
'Without a doubt.',
'Yes - definitely.',
'You may rely on it.',
'As I see it, yes.',
'Most likely.',
'Outlook good.',
'Yes.',
'Signs point to yes.',
'Reply hazy, try again.',
'Ask again later.',
'No.',
'Better not tell you now.',
'Cannot predict now.',
'Concentrate and ask again.',
"Don't count on it.",
'My reply is no.',
'My sources say no.',
'Outlook not so good.',
'Very doubtful.']
responses = random.choice(responses)
embed=discord.Embed(title="8ball", description="Ask the 8ball!", color=discord.Color.dark_purple())
embed.add_field(name="Q: " + question, value="A:" + responses, inline=False)
await ctx.send(embed=embed)

You need to have more than one aliases in the aliases =. Try [‘8ball’, ‘8b’]

Related

Discord.py commands.BotMissingPermissions

I want to send an error message when my bot's role is insufficient, but I can't. I tried all the "MissingRole" commands but none of them work...
#Bot.event
async def on_command_error(ctx, error):
if isinstance(error, commands.BotMissingPermissions):
.
.
.
await ctx.channel.send(embed=embed)
if isinstance(error, commands.BotMissingPermissions):
await ctx.message.add_reaction("❌")
aEmbed = discord.Embed(
title=f"**__Error__**",
description="Whatever you want the bot to say to the user",
colour=discord.Colour.red()
)
await ctx.send(embed=aEmbed)
return
This is how I made the "BotMissingPermissions". The code is pretty basic, it just puts a "X" reaction to the message that made the error and then sends an embed saying what went wrong then returns so that it can continue functioning without any problems
Also the response you told the bot to do (await ctx.channel.send("Something something")) could be changed to await ctx.send("Something").

Bot is unresponsive even when a "message.channel.send" await is called. What is wrong?

This discord.py project I have been working on in the past few days has given me nothing but trouble. To state what the issue is here. Basically the entire application is unresponsive, even when every await and every intent is enabled(on the commands.Bot main.py this is just an extension). I have tried every solution possible. I tried retyping keys and values for the dictionaries. And I even removed the embedded messages and replaced them with normal string messages. And I still got nothing. Here is a little snippet of the "problem". Anyways, I'd appreciate it if I could get some help on this?
#commands.Cog.listener()
async def on_message(self, message, member:discord.Member=None):
ARI=discord.utils.get(message.guild.roles,name=teamnames['ARI'])
ATL=discord.utils.get(message.guild.roles,name=teamnames['ATL'])
if message.content.startswith('<:ARI:844709003871387648> sign'):
member = message.mentions[0]
if ARI or ATL in member.roles:
embed=discord.Embed(title="Signing Failed", description=f"**{member.mention} Wasnt Signed due to there being another team role in that users role. If this is incorrect, have this user either: \nAsk for Release or Demand from the team that they are currently roled as. . .**")
await message.channel.send(embed=embed)
else:
embed=discord.Embed(title="Signing Transaction", description=f"**{member.mention} Was Signed to the <:ARI:844709003871387648> as the **`{len(ARI.members)}`** Player Signed Accordingly. If this was an error use command: <:ARI:844709003871387648> **`Release #user.mention`** To release the player of your initially signed roster.")
await member.add_roles(ARI)
await message.channel.send(embed=embed)
Resolved the issue by reverting to dictionary keys and values, but a new error is now showing. And the bot is still for some reason unresponsive? Snippet below:
#commands.Cog.listener()
#commands.has_any_role('Franchise Owner', 'General Manager', 'Head Coach')
async def on_message(self, message):
if 'have signed' in message.content:
member = message.mentions[0]
teamemojis = ["ARI", "ATL", "BAL", "BUF", "CAR", "CHI", "CIN", "CLE"]
teamsids = [784827425422573608, 784827426093793330, 784827440324804639, 784827439221047317, 784827427029385246, 784827427796025364, 784827441205477386, 784827442174623745,]
teams=[]
if teamsids.id in teamsids:
teams.append(teamsids.id)
step2=str(teams)
step3=step2.replace("[","")
step4=step3.replace("]","")
print(step4)
step5=teamsids.index(int(step4))
print(step5)
emote=discord.utils.get(message.guild.emojis,name=teamemojis[step5])
team = discord.utils.get(message.guild.roles,id=int(step4))
pass
if team not in message.author.roles:
print('return')
return
elif team in message.author.roles:
print('pass')
pass
if team not in member.roles:
for role in message.author.roles:
role.name == team.name
await member.add_roles(role, reason="Signed by the Bot!")
embed=discord.Embed(title="Signing Transaction", description=f"**{member.mention} Was Signed to the {str(emote)} accordingly. If this was a mistake, please refer to the `have released` Command in the bot commands**")
embed.set_thumbnail(url=emote.url)
await message.channel.send(embed=embed)
elif team in member.roles:
await message.channel.send("**Cannot sign this user, as this user is already signed!**")
return
For an on_message event. Read the docs here: https://discordpy.readthedocs.io/en/stable/faq.html#why-does-on-message-make-my-commands-stop-working
Adding the line:
await bot.process_commands(message)
at the bottom of the on_message event should make it function correctly again

Discord.py embed is only showing one word

So I'm trying to make a !say (message goes here) command for my discord bot. Here's the code I've got so far:
async def say(ctx, message):
embed=discord.Embed(title="New Say Message", description=(message), color=0xff0000)
await ctx.send(embed=embed)
If I do "!say Hello", it works fine. However, if I do "!say How are you", it just shows the word "How" in the embed. Here's what I mean: https://gyazo.com/b146fff6c1d7c99a47db9c218dd753f1.
What do I need to do/change to make it show the full message. Thanks!
Your function signature is set up incorrectly. You only accept one argument from the bot with async def say(ctx, message); in order to consume a variable-length of arguments in python, you need *. Then you would consume that variable length as a list.
Example:
async def say(ctx, *message):
embed=discord.Embed(title="New Say Message", description=(" ".join(message)), color=0xff0000)
await ctx.send(embed=embed)

How to make a Discord Bot reply to a specific message rather than every message including a word

I have a bot that I want to reply to a specific word, and it does. However, if you type any message including that word, it will also reply. How do I stop that?
For example. If I was to say "Who", the bot would reply with "go away lucas"
However, if I was to say "Who is this person?" the bot would still reply with "go away lucas"
Is there any fix to this? Thanks!
async def on_message(message):
if message.content.startswith('who'):
msg = 'who'.format(message)
await message.channel.send('go away lucas')
await bot.process_commands(message)
I see you are using startswith().
the command startswith() returns True if the message starts with the desired string for example:
a = "who"
b = "who is lucas"
print(a.startswith("who"))
print(b.startswith("who"))
The output will be:
True
True
If you want the command to work only when the content of the message is "who", try this:
async def on_message(message):
if message.content == "who":
msg = 'who'.format(message)
await message.channel.send('go away lucas')
await bot.process_commands(message)

"except" function not working with discord.py

I am new to developing discord bots and have encountered an issue. the "except" function is not working and draws a syntax error.
The error that it draws is here:
File "bot.py", line 36
except MissingRequiredArgument:
^
SyntaxError: invalid syntax
And the code is here:
import random
from discord.ext import commands
client = commands.Bot(command_prefix = '.')
#client.event
async def on_ready():
print("Bot is ready!")
await client.change_presence(activity = discord.Game("with fire"))
#client.command()
async def eightball(ctx, *, question):
repsonses = [ 'It is certain.',
'It is decidedly so.',
'Without a doubt.',
'Yes – definitely.',
'You may rely on it.',
'As I see it, yes.',
'Most likely.',
'Outlook good.',
'Yes.',
'Signs point to yes.',
'Reply hazy, try again.',
'Ask again later.',
'Better not tell you now.',
'Cannot predict now.',
'Concentrate and ask again.',
"Don't count on it.",
'My reply is no.',
'My sources say no.',
'Outlook not so good.',
'Very doubtful.']
embed = discord.Embed(title="Fireplace", description=(f'{repsonses[random.randint(0, 20)]}'), colour = discord.Colour.orange())
embed.set_footer(text = " By logiccc", icon_url="https://pbs.twimg.com/media/C6F-YfVUwAE91mv.jpg")
await ctx.send(embed=embed)
except:
embed = discord.Embed(title="Fireplace", description=("Sorry! Something went wrong... The command syntax is .eightball <question>"), colour = discord.Colour.orange())
embed.set_footer(text = " By logiccc", icon_url="https://pbs.twimg.com/media/C6F-YfVUwAE91mv.jpg")
#client.command()
async def ping(ctx):
embed = discord.Embed(title="Fireplace", description="Pong!", colour = discord.Colour.orange())
embed.set_footer(text = " By logiccc", icon_url="https://pbs.twimg.com/media/C6F-YfVUwAE91mv.jpg")
await ctx.send(embed=embed)```
I have no idea why this happens. Anyone else know?
Edit: I have tried the code in the comment but it doesn't work. I just keep getting the error message in the console and no reply from the bot. Any tips?
You are using try-except the wrong way, take a look at the comments I left in the code below. You can learn about it here.
#client.command()
async def eightball(ctx, *, question):
repsonses = ['It is certain.',
'It is decidedly so.',
'Without a doubt.',
'Yes – definitely.',
'You may rely on it.',
'As I see it, yes.',
'Most likely.',
'Outlook good.',
'Yes.',
'Signs point to yes.',
'Reply hazy, try again.',
'Ask again later.',
'Better not tell you now.',
'Cannot predict now.',
'Concentrate and ask again.',
"Don't count on it.",
'My reply is no.',
'My sources say no.',
'Outlook not so good.',
'Very doubtful.']
try: # Try to do this
embed = discord.Embed(title="Fireplace", description=(f'{repsonses[random.randint(0, 20)]}'),
colour=discord.Colour.orange())
embed.set_footer(text=" By logiccc", icon_url="https://pbs.twimg.com/media/C6F-YfVUwAE91mv.jpg")
await ctx.send(embed=embed)
except: # If can't then do this
embed = discord.Embed(title="Fireplace", description=(
"Sorry! Something went wrong... The command syntax is .eightball <question>"),
colour=discord.Colour.orange())
embed.set_footer(text=" By logiccc", icon_url="https://pbs.twimg.com/media/C6F-YfVUwAE91mv.jpg")

Resources