discord.py Spotify doesnt seem to do anything
Question:
I’m developing my first bot just as a hobby and something to help me learn some Python and I’ve been trying to integrate Spotify with it but it just doesn’t seem to work. I also read the other post on this website but it did not help.
I have tried reading through the documentation but I am a beginner and could not find much on google to help.
if I do print(discord.Spotify.title), I get this <property object at 0x0000020E42C5DE00>
This is the code I tried to use but did not work:
from discord import Spotify
@bot.command()
async def spotify(ctx, user: discord.Member = None):
if user == None:
user = ctx.author
pass
if user.activities:
for activity in user.activities:
if isinstance(activity, Spotify):
embed = discord.Embed(title = f"{user.name}'s Spotify", description = "Listening to{}".format(activity.title), color = 0xC902FF)
embed.set_thumbnail(url=activity.album_cover_url)
embed.add_field(name="Artist", value=activity.artist)
embed.add_field(name="Album", value=activity.album)
embed.set_footer(text="Song started at {}".format(activity.created_at.strftime("%H:%M")))
await ctx.send(embed=embed)
Apologies for any formatting issues. Not sure if I used the code block correctly
I am also using cogs if it makes a difference at all.
Just want it to at least send me back a message with the song the user is playing so I can have it respond differently to different artists or songs.
Thanks!
Answers:
You can try to check if it is a problem with your Intents. Import all
with the following function:
intents = discord.Intents.all()
client = discord.Client(intents=intents)
Connected with a code the following command works fine for me:
from discord import Spotify
@bot.command()
async def spotify(ctx, user: discord.Member = None):
if user == None:
user = ctx.author
pass
if user.activities:
for activity in user.activities:
if isinstance(activity, Spotify):
embed = discord.Embed(title = f"{user.name}'s Spotify", description = "Listening to{}".format(activity.title), color = 0xC902FF)
embed.set_thumbnail(url=activity.album_cover_url)
embed.add_field(name="Artist", value=activity.artist)
embed.add_field(name="Album", value=activity.album)
embed.set_footer(text="Song started at {}".format(activity.created_at.strftime("%H:%M")))
await ctx.send(embed=embed)
The output:
I was having the same issue.
After adding this line:
intents = discord.Intents().all()
you need to add intents to the bot parameter:
bot = commands.Bot(command_prefix = "?", intents=intents)
I’m developing my first bot just as a hobby and something to help me learn some Python and I’ve been trying to integrate Spotify with it but it just doesn’t seem to work. I also read the other post on this website but it did not help.
I have tried reading through the documentation but I am a beginner and could not find much on google to help.
if I do print(discord.Spotify.title), I get this <property object at 0x0000020E42C5DE00>
This is the code I tried to use but did not work:
from discord import Spotify
@bot.command()
async def spotify(ctx, user: discord.Member = None):
if user == None:
user = ctx.author
pass
if user.activities:
for activity in user.activities:
if isinstance(activity, Spotify):
embed = discord.Embed(title = f"{user.name}'s Spotify", description = "Listening to{}".format(activity.title), color = 0xC902FF)
embed.set_thumbnail(url=activity.album_cover_url)
embed.add_field(name="Artist", value=activity.artist)
embed.add_field(name="Album", value=activity.album)
embed.set_footer(text="Song started at {}".format(activity.created_at.strftime("%H:%M")))
await ctx.send(embed=embed)
Apologies for any formatting issues. Not sure if I used the code block correctly
I am also using cogs if it makes a difference at all.
Just want it to at least send me back a message with the song the user is playing so I can have it respond differently to different artists or songs.
Thanks!
You can try to check if it is a problem with your Intents. Import all
with the following function:
intents = discord.Intents.all()
client = discord.Client(intents=intents)
Connected with a code the following command works fine for me:
from discord import Spotify
@bot.command()
async def spotify(ctx, user: discord.Member = None):
if user == None:
user = ctx.author
pass
if user.activities:
for activity in user.activities:
if isinstance(activity, Spotify):
embed = discord.Embed(title = f"{user.name}'s Spotify", description = "Listening to{}".format(activity.title), color = 0xC902FF)
embed.set_thumbnail(url=activity.album_cover_url)
embed.add_field(name="Artist", value=activity.artist)
embed.add_field(name="Album", value=activity.album)
embed.set_footer(text="Song started at {}".format(activity.created_at.strftime("%H:%M")))
await ctx.send(embed=embed)
The output:
I was having the same issue.
After adding this line:
intents = discord.Intents().all()
you need to add intents to the bot parameter:
bot = commands.Bot(command_prefix = "?", intents=intents)