Error using commands.Greedy in Discord.py Rewrite - discord

Whenever I try to use commands.Greedy I keep get AttributeError: module 'discord.ext.commands' has no attribute 'Greedy'. Here's my code:
#client.command(description="Kicks user", usage="[#user(s)]", brief="Kicks user")
#commands.has_role(settings.admin_role_name)
async def kick(self, ctx, targets: commands.Greedy[discord.Member], *reason: str):
for target in targets:
await target.kick(reason="{} ({}) used .kick command with the reason {}".format(ctx.message.author.name, ctx.message.author.id, reason))
await ctx.send("<#{}> kicked <#{}>\n**Reason:** {}".format(ctx.message.author.id, target.id, reason))
#client.command(description="Bans user", usage="[#user]", brief="Bans user")
#commands.has_role(settings.admin_role_name)
async def ban(self, ctx, targets: commands.Greedy[discord.Member], *reason: str):
for target in targets:
await target.ban(reason="{} ({}) used .kick command with the reason {}".format(ctx.message.author.name, ctx.message.author.id, reason))
await ctx.message.channel.send("{} banned <#{}>\n**Reason:** {}".format(ctx.message.author.id, target.id, reason))
My discord version is discord.py 1.0.0a1561+g53433bc

I reinstalled discord.py, turns out I had a old version that didn't have this

Related

Error with discord bot 1.7.3 giving very long error

I was trying to make a discord chat bot but I got this error I am not sure what to do by the way I am using discord 1.7.3 here is the code by the way the DISCORD KEY and OPENAI-KEY are not the problem those are to hide my openai key and discord bot key:
import discord
import asyncio
import openai
import os
openai.api_key = os.environ.get('OPENAI-KEY')
client = discord.Client()
#client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
elif message.content.startswith('$chat'):
response = openai.Completion.create(
engine="davinci",
prompt=message.content[5:],
max_tokens=100,
temperature=0.9,
top_p=1,
n=1,
stream=False,
logprobs=None,
stop=["\n"],
)
await message.channel.send(response['choices'][0]['text'])
client.run(os.environ.get('DISCORD-TOKEN'))
Here is the error I am getting:
import discord
import asyncio
import openai
import os
openai.api_key = os.environ.get('OPENAI-KEY')
client = discord.Client()
#client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
elif message.content.startswith('$chat'):
response = openai.Completion.create(
engine="davinci",
prompt=message.content[5:],
max_tokens=100,
temperature=0.9,
top_p=1,
n=1,
stream=False,
logprobs=None,
stop=["\n"],
)
await message.channel.send(response['choices'][0]['text'])
client.run(os.environ.get('DISCORD-TOKEN'))
Here is the error I am getting
Traceback (most recent call last):
File "c:\Users\Private\OneDrive\Desktop\Pro\GitHub Repo\Discord_chat_bot\Bot.py", line 35, in <module>
client.run(os.environ.get('DISCORD-TOKEN'))
File "C:\Users\Private\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 723, in run
return future.result()
File "C:\Users\Private\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 702, in runner
await self.start(*args, **kwargs)
File "C:\Users\Private\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 665, in start
await self.login(*args, bot=bot)
File "C:\Users\Private\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py", line 511, in login
await self.http.static_login(token.strip(), bot=bot)
AttributeError: 'NoneType' object has no attribute 'strip'
I was expecting for it to work if I try this code in 2.0.0 discord it give a different error
The reason I am using 1.7.3 not 2.0.0 is because I had a different error and to fix it I had to switch to 1.7.3
Error on this line:
client.run(os.environ.get('DISCORD-TOKEN'))
The token you are passing in is None because os.environ.get('DISCORD-TOKEN') returns None.
You could have forgot to set your environment variable or you had it in a .env file. If you have it in a .env file, please load it:
from dotenv import load_dotenv
load_dotenv()

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)

self bot house or name changing

When I try to use
#bot.command()
async def house(ctx):
await bot.user.edit(house="Brilliance")
It raises an error
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: ClientException: Password is required
How can I login with email and password?
Simply pass the password:
#bot.command()
async def house(ctx):
await bot.user.edit(house="Brilliance", password="my password")

Warnings Command

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

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