Issue with playing audio - discord.py - python

ok, so I added this to my bot:
if message.content.startswith('!test'):
voice = await client.join_voice_channel(message.author.voice.voice_channel)
args = message.content.split(" ")
betterargs = " ".join(args[1:])
player = await voice.create_ytdl_player('https://www.youtube.com/watch?v=' + betterargs)
player.start()
but when I type !test and with the end of a youtube link in the chat, the bot joins the channel, but it gives me this error
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\server\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "noob.py", line 99, in on_message
voice = await client.join_voice_channel(message.author.voice.voice_channel)
File "C:\Users\server\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\client.py", line 3211, in join_voice_channel
Anyone knows whats going on?

That property (create_ytdl_player) has been removed in rewrite versions (1.x) of discord.py. Please check the example from the discord.py github repository for more info. (It has a music bot example that used youtube-dl)

Related

I want to make my bot "listening" to something

I am trying to make my discord bots status say listening to you. I have tried various metods I found. This is the only one that haven't made my bot stop working:
#client.event
async def on_ready():
client.user.setActivity('you', { type: 'LISTENING' });
With this my bot is still up, but it doesnt show a status. I also get this error message:
Ignoring exception in on_ready
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
await coro(*args, **kwargs)
File "main.py", line 9, in on_ready
client.user.setActivity('to you', { type: 'LISTENING' });
AttributeError: 'ClientUser' object has no attribute 'setActivity'
Please ask I forgot to include something important.
Read the links:
https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.change_presence
https://discordpy.readthedocs.io/en/stable/api.html#discord.Client.activity
https://discordpy.readthedocs.io/en/stable/api.html#discord.ActivityType
https://discordpy.readthedocs.io/en/stable/api.html#discord.Spotify.type
setActivity does not exist. ActivityType.listening only exists via discord.Spotify.
You change your activity with change_presence:
game = discord.Game("with the API")
await client.change_presence(status=discord.Status.idle, activity=game)
song = discord.Spotify(...)
await client.change_presence(status=discord.Status.idle, activity=song)
setActivity is from discord.js. You are however programming in Python and you are using discord.py.

Discord.py rewrite bot won't change my nickname

I've been learning Python 3.8 by building a Discord bot for my small server of friends. I want my friends to be able to change my nickname, but Discord doesn't seem to allow that unless I give everyone the same rank.
My idea was to give my bot the highest role and let them use a bot command to change my nickname (which would be the second-highest role), but I get the following error:
Traceback (most recent call last):
File "/home/cqqlguy/.local/lib/python3.8/site-packages/discord/client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "/home/cqqlguy/CQQLBOT/CQQLBOT.py", line 516, in on_message
await cqqluser.edit(nick = newnick)
File "/home/cqqlguy/.local/lib/python3.8/site-packages/discord/member.py", line 601, in edit
await http.edit_member(guild_id, self.id, reason=reason, **payload)
File "/home/cqqlguy/.local/lib/python3.8/site-packages/discord/http.py", line 241, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions
The relevant code looks like this:
#bot.event
async def on_message(message):
lowermess = message.content
dMess = lowermess.lower()
if dMess.startswith("$changenick "):
newnick = lowermess.split(" ", 1)[1] #whatever the user enters after the command
changeuser = guild.get_member(id) #id would be my user ID
await changeuser.edit(nick = newnick)
This seems to work on users that aren't me, but the bot has been given a higher role than everyone so I'm not sure why it's not changing it for me.

helpme command, cannot find author's voice channel discord.py

There are bots that you can do !h and the bot types in chat (authors name, need help, #staff, and in which voice channel is the person who need the help)
How could I find the command author's voice channel?
thats what i tried:
(I am trying it on the on_message event for now)
#client.event
async def on_message(message):
print(f'member is in {message.author.voice_channel}')
But when I'm running it and typing something in the chat I receive this error:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\Ido Shaked\Desktop\citybot\venv\lib\site-packages\discord\client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "C:/Users/Ido Shaked/Desktop/citybot/citycode.py", line 18, in on_message
print(f'member is in {message.author.voice_channel}')
AttributeError: 'Member' object has no attribute 'voice_channel'
The error is telling you exactly what's wrong - a Member does not have a voice_channel attribute. You have to get it via message.author.voice.channel

Discord.py I am trying to make a bot react to images sent in a specific channel

So i am trying to make the bot react to images sent in a channel. To my suprise the code works
#commands.Cog.listener()
async def on_message(self, message):
if message.channel.id == 765992140115017758:
await message.add_reaction("<:upvote:762456415751110697>")
however even though this works i keep getting an error every time someone sends an image in the channel
Traceback (most recent call last): File
"/app/.heroku/python/lib/python3.6/site-packages/discord/client.py",
line 333, in _run_event await coro(*args, **kwargs) File
"/app/extras/misc.py", line 71, in on_message await
message.add_reaction("<:upvote:762456415751110697>") File
"/app/.heroku/python/lib/python3.6/site-packages/discord/message.py",
line 996, in add_reaction await
self._state.http.add_reaction(self.channel.id, self.id, emoji) File
"/app/.heroku/python/lib/python3.6/site-packages/discord/http.py",
line 243, in request raise NotFound(r, data) discord.errors.NotFound:
404 Not Found (error code: 10008): Unknown Message
and i am frustrated as heck any help would be appreciated :)

(discord.py) İ want to make a roll call bot for a discord server

I want to make a discord bot. Here is what i want: When i say '!yoklama 11.10.2020.txt'(or something) bot sends me a list of participants of which voice channel i am in.[not 1 channel(which i am in)] But i dont know how can i do.
Then i was some research and i find similar things about my request.
But they did not work properly.
Here is my found codes:
import discord
from discord.ext.commands import Bot
from discord.ext import commands
client = commands.Bot(command_prefix='!')
#client.command()
async def attendance(ctx, filename):
channel = client.get_channel(755129236397752441) # Replace with voice channel ID
with open(filename, 'w') as file:
for member in channel.members:
file.write(member.name + '\n')
client.run('mytoken')
This codes are working(when i run they dont give me error) but when i say !attendence test.txt bot
does not say anything and my python shell say to me:
Ignoring exception in command attendance:
Traceback (most recent call last):
File "C:\Users\Yunus Emre KISA\AppData\Local\Programs\Python\Python38-32\lib\site-
packages\discord\ext\commands\core.py", line 85, in wrapped
ret = await coro(args, **kwargs)
File "C:\bot2\bot2.py", line 10, in attendance
for member in channel.members:
AttributeError: 'NoneType' object has no attribute 'members'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Yunus Emre KISA\AppData\Local\Programs\Python\Python38-32\lib\site-
packages\discord\ext\commands\bot.py", line 903, in invoke
await ctx.command.invoke(ctx)
File "C:\Users\Yunus Emre KISA\AppData\Local\Programs\Python\Python38-32\lib\site-
packages\discord\ext\commands\core.py", line 859, in invoke
await injected(ctx.args, **ctx.kwargs)
File "C:\Users\Yunus Emre KISA\AppData\Local\Programs\Python\Python38-32\lib\site-
packages\discord\ext\commands\core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError:
'NoneType' object has no attribute 'members
You see guys i dont understand anything please help me.
I found these question but it does not work for me:
Discord Python bot creating a file of active member in a vocal channel
#client.command()
async def test(ctx):
guild = ctx.guild
channel = discord.utils.get(guild.voice_channels, name='General')
for member in channel.members:
print('test')
What I would do instead of having to pass in the file in the command, is just in the function writing:
with open("file.txt", "w") as f:

Categories

Resources