Warnings Command - discord

Hello I need help with my warning command. I don't know how to make it say the stuff in chat, if you do show me how to fix this, I would preferably want this in an embed.
#bot.command(pass_context = True)
#has_permissions(manage_roles=True, ban_members=True)
async def warn(ctx,user:discord.User,*reason:str):
if not reason:
await ctx.send("Please provide a reason")
return
reason = ' '.join(reason)
for current_user in report['users']:
if current_user['name'] == user.name:
current_user['reasons'].append(reason)
break
else:
report['users'].append({
'name':user.name,
'reasons': [reason,]
})
with open('reports.json','w+') as f:
json.dump(report,f)
#bot.command(pass_context = True)
async def warnings(ctx,user:discord.User):
for current_user in report['users']:
if user.name == current_user['name']:
await ctx.send(f"```{user.name} has been reported {len(current_user['reasons'])} times : {','.join(current_user['reasons'])}```")
break
else:
await ctx.send(f"```{user.name} has never been reported```")
#warn.error
async def kick_error(error, ctx):
if isinstance(error, MissingPermissions):
text = "Sorry {}, you do not have permissions to do that!".format(ctx.message.author)
await bot.send_message(ctx.message.channel, text)

for and embed put in code. e.g:
embed = discord.Embed(title=f'{member}\'s Warning!',color=0x1d9521)
embed.add_field(name='why he is warned',value=reason, inline=False)
embed.add_field(name="Moderator that warned", value={ctx.author.mention}, inline=False)
i am not sure if this would work but then to send it do
await ctx.send(embed=embed)
another way to send is
await ctx.reply(embed=embed)
to put this out of the embed you could do
await ctx.send("Why they are warned `{reason}`/nThe Responsible Moderator {ctx.author.mention}")
i am not sure if this would work but you can try

Related

Created a code to greet the user and made an embed, no errors except one

Created a code to greet the user and made an embed, no errors except one:
My code:
#client.command()
async def on_member_join(ctx):
await client.fetch_channel(id)(869212882968145992)
embed=discord.Embed(title="new member", description="oook", color=0xFFFF00)
embed.add_field(name="Command1", value="What it does", inline= True)
embed.add_field(name="Command2", value="What it does", inline= True)
await ctx.send( embed = embed)
Error:
'NoneType' object has no attribute 'id'
You already specified the id parameter, put this:
await client.fetch_channel(869212882968145992)
Instead of:
await client.fetch_channel(id)(869212882968145992)

ban command if member is None: [discord.py]

#bot.command()
#commands.has_permissions(ban_members=True)
async def ban (ctx, member:discord.User, reason =None):
if member is None:
await ctx.channel.send("I have no one to ban")
return
if member == ctx.message.author:
await ctx.channel.send("you can't ban yourself")
return
await ctx.guild.ban(member)
await ctx.channel.send(f"{member} was banned")
this is my code
I need to fix:
if member is None:
await ctx.channel.send("I have no one to ban")
return
error :
member is a required argument that is missing.
Put the default value of member as None like this, then it won't be a required arg anymore
async def ban (ctx, member:discord.User = None, reason =None):
add this to your code:
#ban.error
async def ban_error(ctx, error):
if isinstance(error, commands.MemberNotFound):
await ctx.send('I could not find that member...')
This is a error handler
It also prevents member logging :D

Discord.py. How can I wait_for person's reaction inside "on_raw_reaction_add" function?

I need to get the reaction of the user from his private channel. Is this the right way to do that?
#bot.event
async def on_raw_reaction_add(payload):
reactioneer = payload.member
emoji = payload.emoji
if emoji.name == "🔰":
msg = await reactioneer.send("Hi! Which greeting would you like to hear every morning? Click the reaction of it. Hello - 1, Morning - 2...")
await msg.add_reaction(:one:)
await msg.add_reaction(:two:)
def check(user, payload):
return user == payload.member and message.channel.type == discord.ChannelType.private
await bot.wait_for("payload", check = check)
### some things with data bases (does not matter now)
await reactioneer.send("Alright, I will send this greeting every morning!")
await bot.wait_for("raw_reaction_add", check=check)
bot.wait_for() waits for a WebSocket event to be dispatched.

How to get a bot to save the message after a trigger word (discord.py)

I'm trying to get my bot to respond to a message sent after a trigger word, but all it does is send me the following error: AttributeError: 'generator' object has no attribute 'content'. Here is my code:
#client.event
async def on_message(message):
if message.content == "report":
await message.author.send("Type your report below")
def check(m):
return m.guild == None and m.author == message.author
try:
response = client.wait_for("message", check=check)
except asyncio.TimeoutError:
await message.author.send("Uh-oh, the request timed out! Try again.")
else:
content = response.content
Thanks in advance!
client.wait_for is a coroutine function. That means, in order to use it, you have to await it.
You just have to do:
response = await client.wait_for("message", check=check)

Improving upon discord MassDM bot

import discord
from discord.ext import commands
import platform
import random
import time
bot = commands.Bot(command_prefix='+', case_insensitive=True)
#bot.event
async def on_ready():
print(f'Logged in as {bot.user.name}(ID: +{bot.user.id}) |'
f'Connected to {str(len(bot.guilds))} servers |'
f'Connected to {str(len(set(bot.get_all_members())))} users')
print('--------')
print('CREATED AND HOSTED BY Fataldagod | Fixed Version')
#bot.event
async def on_command_error(ctx, error):
# Ignore these errors:
ignored = (
commands.CommandNotFound, commands.UserInputError, commands.BotMissingPermissions,
commands.MissingPermissions, discord.errors.Forbidden, commands.CommandInvokeError,
commands.MissingRequiredArgument)
if isinstance(error, ignored):
return
#bot.command(pass_context=True)
#commands.has_permissions(kick_members=True)
async def userinfo(ctx, user: discord.Member):
try:
embed = discord.Embed(title="{}'s info".format(user.name),
description="Here's what I could find.",
color=discord.Colour.dark_red())
embed.add_field(name="Name", value=user.name, inline=True)
embed.add_field(name="ID", value=user.id, inline=True)
embed.add_field(name="Status", value=user.status, inline=True)
embed.add_field(name="Highest role", value=user.top_role)
embed.add_field(name="Joined", value=user.joined_at)
embed.set_thumbnail(url=user.avatar_url)
await ctx.send(embed=embed)
except:
await ctx.send("Missing Requrired Args")
#commands.has_permissions(administrator=True)
#bot.command(pass_context=True)
async def send(ctx, *, content: str):
for member in ctx.guild.members:
c = await member.create_dm()
try:
await c.send(content)
await ctx.send("MassDM message sent to: {} ".format(member))
except Exception:
await ctx.send("MassDM message blocked by: {} ".format(member))
Was wondering what I can change to make it so the bot DMs specific roles rather than the entire server?
For example instead of me typing +send (message) I'd like to type +send #role1 #role2 role3 #role4 (message) or something along these lines.
Any help is much appreciated.

Resources