get channel name discord.py code example
Example 1: python discord
import discord
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as', self.user)
async def on_message(self, message):
if message.author == self.user:
return
if message.content == 'ping':
await message.channel.send('pong')
client = MyClient()
client.run('token')
Example 2: discord.py get channel id by channel name
channel = discord.utils.get(server.channels, name="Channel_name_here", type="ChannelType.voice")
Example 3: create a role with discord.py
@client.command(aliases=['make_role'])
@commands.has_permissions(manage_roles=True)
async def create_role(ctx, *, name):
guild = ctx.guild
await guild.create_role(name=name)
await ctx.send(f'Role `{name}` has been created')
Example 4: discord.py get channel id by channel name
channel_names = ['channel1', 'channel2', 'channel3']
for ch in channel_names:
channel = discord.get.utils(server.channels, name=ch, type="ChannelType.voice")
full(channel)