#client.command(pass_context=True)
async def join(ctx):
channel = ctx.message.author.voice.voice_channel
await client.join_voice_channel(channel)
In this command when i run it and type join it doesn't join voice channel, it says 'VoiceState' object has no attribute 'voice_channel'
client.command()
async def join(ctx):
channel = ctx.author.voice.channel
await channel.connect()
Related
I want the message to get sent to a specific channel
async def on_message_edit(before, after):
await before.channel.send(
f'{before.author} edited a message.\n'
f'Before: {before.content}\n'
f'After: {after.content}'
)
To send a message in a specific channel you need first to fetch the choosed channel by using his id by using get_channel() like this:
specificChannel = bot.get_channel(int(YOUR_CHANNEL_ID_HERE))
Then your event block should look like this:
#client.event
async def on_message_edit(before, after):
specificChannel = bot.get_channel(int(YOUR_CHANNEL_ID_HERE))
await specificChannel.send(
f'{before.author} edited a message.\n'
f'Before: {before.content}\n'
f'After: {after.content}'
)
Useful link:
get_channel()
Discord.py documentation
maybe this can help u :)
#client.event
async def on_member_join(member:Member):
if member.bot:
guild:discord.Guild = member.guild
role = guild.get_role(config.botRoleID)
channel:discord.TextChannel = guild.get_channel(YOUR_CHANNEL_ID)
await member.add_roles(role)
await channel.send(f'Set Bot role to "{member.display_name}" 😌')
I am new to coding so sorry if this is easy to do. But what I am wanting to have my bot do is send a message to my private guild when it is added or removed from another guild. Also if it could say the name of said guild that would help as well.
#client.event
async def on_guild_join(guild):
chn = client.get_channel(YOUR_PRIVATE_GUILD_CHANNEL_ID)
embed = discord.Embed(title=f"Bot Invited",description=f"""
**User Name:** {bot_entry[0].user.name}
**User ID:** {bot_entry[0].user.id}
**Server Name:** {guild.name}
**Server ID:** {guild.id}
**Members Count:** {len(guild.members)}
""", colour=0x2dc6f9)
embed.set_footer(icon_url=guild.icon_url, text=guild.name)
embed.set_author(name=f"{bot_entry[0].user.name}#{bot_entry[0].user.discriminator}", icon_url=bot_entry[0].user.avatar_url)
embed.timestamp = datetime.datetime.utcnow()
server_invite = await guild.text_channels[0].create_invite(max_age = 0, max_uses = 0)
await chn.send(f"{server_invite}", embed=embed)
Something like this?
#client.event
async def on_guild_join(guild):
await client.get_channel(idchannel).send(f"{client.name} has joined")
I am using code that I found here.
But, I'm getting an error that the client object doesn't have the attribute send_message. I have tried message.channel.send but that failed as well.
#client.event
async def on_ready():
Channel = client.get_channel('YOUR_CHANNEL_ID')
Text= "YOUR_MESSAGE_HERE"
Moji = await client.send_message(Channel, Text)
await client.add_reaction(Moji, emoji='🏃')
#client.event
async def on_reaction_add(reaction, user):
Channel = client.get_channel('YOUR_CHANNEL_ID')
if reaction.message.channel.id != Channel:
return
if reaction.emoji == "🏃":
Role = discord.utils.get(user.server.roles, name="YOUR_ROLE_NAME_HERE")
await client.add_roles(user, Role)
One of the reasons why your code might not be working is because you may have your channel id stored in a string. Your code shows:
Channel = client.get_channel('YOUR CHANNEL ID')
The code above shows that your channel id is stored in a string, which it should not be. With the code above, your actual code may look like this:
Channel = client.get_channel('1234567890')
Instead you should have:
Channel = client.get_channel(1234567890)
This is the code I got so far but for some reason, it doesn't really work...
async def on_ready():
Channel = client.get_channel('777877476558110737')
Text= "React to Verify"
Moji = await client.send_message(Channel, Text)
await client.add_reaction(Moji, emoji='🏃')
#client.event
async def on_reaction_add(reaction, user):
Channel = client.get_channel('777877476558110737')
if reaction.message.channel.id != Channel:
return
if reaction.emoji == "🏃":
Role = discord.utils.get(user.server.roles, name="12 Year Old")
await client.add_roles(user, Role)
Use Channel.send(Text) not client.send_message(Channel, Text) because send_message is not a method of client, but send is a method of Channel.
Use Moji.add_reaction("🏃") not client.add_reaction(Moji, emoji='🏃') because the add_reaction is a method of the Message class.
Change user.server.roles to user.guild.roles because server is not an attribute of the Member class, but guild is.
Use user.add_roles(Role) not client.add_roles(user, Role) because add_roles is a method of the Member class.
Make sure to reference the docs. You are calling many methods from the client when they are supposed to be called from other classes. Update discord.py to the latest version too.
I am making a bot that mutes people when they join a vc. However, when I run the following code I receive an error about 'self' not being defined. How would I fix this?
async def join(ctx, *, member=discord.Member):
channel = ctx.author.voice.channel
await channel.connect()
await member.edit(mute=True)
If you're inside a Class/Cog you need to pass self as the first parameter.
async def join(self, ctx, *, member=discord.Member):
channel = ctx.author.voice.channel
await channel.connect()
await member.edit(mute=True)