I want to output the connected voice channel to the channel by inputting the user ID - discord.py

I want to output the connected voice channel to the channel by inputting the user ID.
How do I code it?
I'm using a Google Translator.
Please understand that the translation is strange :)
import discord
Me: !s userID
bot : This user is connecting to the #voicechannel.

You need to check member.voice.voice_channel
#bot.command(pass_context=True)
async def whatchannel(ctx, member: discord.Member):
channel = member.voice.voice_channel
if channel is None:
await bot.say(f"{member.mention} is not connected to voice")
else:
await bot.say(f"{member.mention} is connected to {channel.name}")

Related

Find out which voice channels your users are participating in (discord py)

I want to get the ID of the voice channel the user using the current command is participating in.
I got the user's id through interaciton, but I don't know how to find the id of the participating channel.
#tree.command(guild=discord.Object(id=secrets.get('discordsv')), name='randomteam', description='We randomly assign people in the current call room.')
async def randomTeamSet(interaction: discord.Interaction, count: int):
if count <= 1:
await interaction.response.send_message(f"The number of teams is 2 or more.", ephemeral=True)
else:
#Command user's voice channel
print("player voice channel is ")
This should do the trick:
userChannel = interaction.user.voice.channel.id
It should be noted this will error if they are not in a channel.

discord.py creating a bot that sends a specialized preset message in a text channel when specific users join a voice channel

for example when user1 connects to vc1 then "hello user1" is sent in text channel general but when user2 connects to vc1 then "hi user2" is sent in text channel general
im new to coding with discord.py and python in general what would be the easiest way to go about this
below is an example of what i have tried so far
#client.event
async def on_voice_state_update(member, before, after):
print(member)
vc = client.get_channel(id=channel id number)
vc1 = vc.members
if member in vc1[0] == "User#1234":
send msg in general text channel
Your event is well constructed from the point of view, but a little more structure would be good and also some things are completely wrong.
Have a look at the following code:
#client.event
async def on_voice_state_update(member, before, after):
channel = before.channel or after.channel
if channel.id == VoiceChannelID: # Insert voice channel ID
if before.channel is None and after.channel is not None: # Member joins the defined channel
channel1 = client.get_channel(GeneralTextChatID) # Define the general channel
await channel1.send(f"Welcome to the voice channel {member.mention}!") # Mention the member
What did we do?
Checked the channel before and after the user joined (channel=)
Checked if the joined channel matches the defined channel
Sent a message if the channel is correct
Used an f-string to mention the member

how to make a discord.py bot that send embedded message in particular channel when user join a particular voice channel

I am learning discord.py and I want to make bot that sends embedded message like.(#user has joined!) joined in particular text channel only eg.(#music-cnsole) when users join particular voice channel eg.(music.vc)
like this
when user joins
also
when user leaves
#client.event
async def on_voice_state_update(member, before, after):
channelId = 1234567891011 # Your text channel id here
voiceChannelId = 1234567891011 # Your voice channel id here
#bot.event
async def on_voice_state_update(member, before, after):
if ((before.channel != None and before.channel.id == voiceChannelId) or (after.channel != None and after.channel.id == voiceChannelId)): # if connected/disconected to voiceChannelId channel
channel = bot.get_channel(channelId) # gets channel object
if (before.channel == None and after.channel != None): # if user connect
channel.send(f"{member.mention} connected to voice {after.channel.name}") # send message to channel
elif (before.channel != None and after.channel == None): # if user disconnect
channel.send(f"{member.mention} disconnect from voice {before.channel.name}") # send message to channel
on_voice_state_update event in docs
Pardon for many edits.

Discord dm bot that can dm back

I am trying to make a donation bot, where in the channel when a person types !donate the bot will Dm them.
I got all that down but I am trying to make so that the person decides on how to donate like !cashapp, !paypal, etc., in the dms. It would send them that specific way to send money, for example once the bot Dms the use user what service they would like to pay with and the user says !cashapp it will send another message with my cashtag, or if they say !paypal it would send my paypal link.
Here's a simple example:
import discord
from discord.ext import commands
client = commands.Bot(command_prefix = "!")
#client.command()
async def donate(ctx, paymentMethod: str):
if (paymentMethod.lower() == "paypal"):
await ctx.send("PayPal link: ...")
elif (paymentMethod.lower() == "cashapp"):
await ctx.send("Cashapp Link: ...")
else:
await ctx.send("The provided payment method is not available.")
#donate.error
async def donate_error(ctx, error):
if isinstance(error, commands.errors.MissingRequiredArgument):
await ctx.send("Incorrect use of command!")
client.run("your bot token here")
Usage:
!donate {payment method} - Without the '{}'
Check the documentation for more information.
You can use user.send to send a message to the user dm and use it in the same way as ctx.send and channel.send.
await ctx.author.send("paypal link: ...") # ctx.author is the member that call the command
And 2 command will have different function so you just need to write both of them in a different way.
If you planning to make it into 1 command you can use if else check
#client.command(pass_context=True)
async def steam(ctx):
if ctx.author.send():
await ctx.send("you not boster")
else:
await ctx.author.send(random.choice(list(open('steam.txt'))))
i want if someone send a dm
its not Returns a dm
someone know how to do this?

Discord Bot sending more than one message

So I am creating a simple bot that detects when somebody joins a server and when somebody leaves the server.
I added a command to show people's avatars, but any time I do it, or when somebody joins or leaves, it sends the message more than once.
I've searched and I can't find the problem.
Can you guys help me?
Here's my code
import discord
from discord.ext import commands
client = commands.Bot(command_prefix="?")
#client.event
async def on_ready():
print("Ready")
#client.event
async def on_member_join(member):
channel = discord.utils.get(member.guild.text_channels, name="entradas")
await channel.send(f"{member} is new on the server, everyone say hi")
show_avatar = discord.Embed(color = discord.Color.blue())
show_avatar.set_image(url="{}".format(member.avatar_url))
await channel.send(embed=show_avatar)
#client.event
async def on_member_remove(member):
channel = discord.utils.get(member.guild.text_channels, name="saidas")
await channel.send(f"{member} left the server, press F to pay respects")
#client.command()
async def avatar(ctx, member: discord.Member):
show_avatar = discord.Embed(color = discord.Color.blue())
show_avatar.set_image(url="{}".format(member.avatar_url))
await ctx.send(embed=show_avatar)
You should check if you are running 2 bots.
If you are running your bot on Linux with screen, simply check with
screen -ls
on windows, just check the task-manager and look under something like Python.
It's btw possible to have the same bot running twice.

Resources