Discord py Music bot getting AtributeError: 'NoneType' object has no attribute 'length' - discord.py

so im following an outdated video of a guy coding discord python music bot and im having a lot of struggle with it. So right now I managed to get it to work but i cant make skip command to work. Apparently im not corectly defining voice_client since is_playing(), queue.is_empty and couple more thins here are just white and when i hover it says : Any. Anyone help ?
`#commands.command(name='skip', aliases=['s'])
async def skip(self, ctx:commands.Context):
channel = self.bot.get_channel(741393771127767151)
if ctx.channel is channel:
vc= ctx.voice_client
if vc:
if not vc.is_playing():
await ctx.send('Nothing is playing.')
if vc.queue.is_empty:
await vc.stop()
await vc.seek(vc.track.length * 1000)
if vc.is_paused():
await vc.resume()
else:
await ctx.send('The bot is not connected to a voice channel.')
else:
await ctx.send(f'Listening to {channel.mention} chat only')`
Im getting this error
await vc.seek(vc.track.length * 1000)
^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'length'
it will probbably throw error for is_playing, empty and couple more related to vc.*
TO make it to skip current song

Related

how to mention a specific channel in a await message

Problem: don't know how to mention a specific channel, it would be nice if some of you could help me
this code run but it doesn't mention the playground channel
#bot.command()
async def prov(ctx):
if ctx.channel.id == 1028873503010717717:
await ctx.send("The bot is disabled in this channel!,\n try in #playground")
else:
If you mention as in just display a clickable link/mention, just use <#channelid>
Eg: <#1283768190123132>

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

How to make a Reaction role command with discord.py

So I'm trying to make a Reaction role via discord.py but i don't know how to do it. Also there is no tutorial on YT, I want the bot to send a message and react to that message so the user when react to that get the role.
Okay,
This uses cogs and a bot instead of a client.
message = await ctx.send(" Click the ✅ reaction to verify yourself")
This piece sends the message (You can change it to whatever you want).
if not get(ctx.guild.roles, name="Verified"):
perms = discord.Permissions()
perms.general()
perms.text()
perms.voice()
await ctx.guild.create_role(name="Verified", permissions=perms, colour=discord.Colour(0x00bd09))
This piece will just check whever the role exists or not. If it doesnt it will create one.
await message.add_reaction("✅")
This adds this reaction to the message(So the user doesnt have to scroll around for it). If you dont want the bot have the role, you can add a check (If the user is a bot or not) in the on_raw_reaction_add() function.
#commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
guild = self.bot.get_guild(payload.guild_id)
role = discord.utils.get(guild.roles, name="Verified")
await payload.member.add_roles(role, reason="Verified Self", atomic=True)
This is the function to check when someone adds a reaction to the message. We want to use on_raw_reaction_add() instead of on_reaction_add() because the second one check the cache for adding a reaction, and if the thing isnt in chache it wont work. Thus the 1st one is less probable to create problems.
Here's the whole piece.
from discord.ext import commands
from discord.utils import get
import discord
from discord.ext.commands import has_permissions, CheckFailure
class Verification(commands.Cog):
def __init__(self, bot):
self.bot = bot
#commands.command(name='generate_verification', help='Generates verification message')
async def generate_verification(self, ctx):
message = await ctx.send(" Click the ✅ reaction to verify yourself")
verification_message_id = message.id
# Check if Verification role already exists
if not get(ctx.guild.roles, name="Verified"):
perms = discord.Permissions()
perms.general()
perms.text()
perms.voice()
await ctx.guild.create_role(name="Verified", permissions=perms, colour=discord.Colour(0x00bd09))
await message.add_reaction("✅")
#commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
guild = self.bot.get_guild(payload.guild_id)
role = discord.utils.get(guild.roles, name="Verified")
await payload.member.add_roles(role, reason="Verified Self", atomic=True)
def setup(bot):
bot.add_cog(Verification(bot))
If you're creating a verification command, then you probably would like to store the amount of verification messages sent in a file. This would stop people from generating the message a lot of times. To this you also probably want a command to clear the data from the file, so if the adming wants to create the message again he just needs to clear the file.

Command raised an exception: AttributeError: 'NoneType' object has no attribute 'system_channel'

I'm trying to make a command where the bot sends me an invite of a server by ,dm (server id) and this is what I made so far:
#client.command(name='dm')
async def dm(ctx, guild_id: int):
if ctx.author.id == owner:
guild = client.get_guild(guild_id)
guildchannel = guild.system_channel
invitelink = await guildchannel.create_invite(max_uses=1,unique=True)
await ctx.author.send(invitelink)
Some servers work and some don't. The ones that don't work sends this: 'NoneType' object has no attribute 'create_invite' and sometimes it sends me 2 invite links of the same server. Please help as soon as possible and thanks in advance.
Your client.get_guild(guild_id) is returning None, this means your bot either isn't in the guild or your guild_id isn't a valid guild ID
UPDATE:
On second thought I think your target server does not have a system_channel. You can check then in your Guild Settings > Overview > System Messages Channel.
So I found a way to change this, here is the code:
#client.command(name='dm')
async def _dm(ctx, guild_id: int):
if ctx.author.id == owner:
guild = client.get_guild(guild_id)
channel = guild.channels[-1]
invitelink = await channel.create_invite(max_uses=1)
await ctx.author.send(invitelink)

Resources