API reference
Channels
Find, create, change, lock and delete channels and threads.
These functions work in commands, events and component handlers.
When a function asks for a channel, you can pass:
- a channel object, like the
channelvariable; - a channel ID, as a number;
- the exact channel name, like
"general".
A channel ID written as text, like "1234", is read as a name and is not found. Use int(...) first.
Write await yourself | No await needed |
|---|---|
lock_channel, unlock_channel, set_slowmode | everything else on this page |
The bot needs permission
Creating, changing and deleting channels needs Manage Channels. Locking needs permission to edit the channel's permissions.
get_channel#
Finds one channel or thread. Returns None when there is no match.
get_channel(channel)log = get_channel("mod-log")
if log is None:
set_error("Make a #mod-log channel first.")get_channels#
With no arguments, returns every channel in the server, without categories and threads. With arguments, returns the channels that match.
get_channels(*channels)count = len(get_channels())
set_content(f"This server has {count} channels.")get_text_channels#
Returns every text channel. Announcement, forum and media channels are included. Threads are not.
get_text_channels()get_voice_channels#
Returns every voice and stage channel.
get_voice_channels()is_thread#
Checks if a channel is a thread. Returns True or False.
is_thread(channel)create_text_channel#
Makes a text channel. Returns the new channel.
create_text_channel(name, **options)Options go to Discord, for example topic, category, nsfw and permission_overwrites.
ticket = create_text_channel(f"ticket-{user.username}", topic=f"Ticket for {user.display_name}")
send_message(ticket, f"{user.mention} a staff member will be with you soon.")create_voice_channel#
Makes a voice channel. Returns the new channel.
create_voice_channel(name, **options)create_category#
Makes a category. Returns the new category.
create_category(name, **options)create_thread#
Makes a thread. Returns the new thread.
create_thread(
channel,
name=None,
message=None,
type="public",
initial_message=None,
)| Argument | What it does |
|---|---|
channel | The channel to make the thread in. |
name | The thread name. Default is "Unnamed". |
message | A message or message ID. The thread starts from that message. |
type | "public" or "private". A thread from a message is always public. |
initial_message | Text the bot posts in the new thread. |
create_thread(channel, name=f"Help for {user.display_name}", type="private",
initial_message=f"{user.mention} describe your problem here.")A message can have only one thread. A second try fails with a clear message.
update_channel#
Changes a channel. Returns the changed channel.
update_channel(channel, **options)update_channel(channel, name="closed-ticket", topic="Closed")delete_channel#
Deletes a channel.
delete_channel(channel)Watch out
A deleted channel cannot come back. Its messages are lost.
lock_channel#
Stops @everyone from sending messages in a channel. Other permissions stay as they are.
await lock_channel(channel=None, reason=None)With no channel, it locks the channel where the command ran.
await lock_channel(reason=f"Locked by {user.display_name}")
set_content("This channel is locked.")unlock_channel#
Lets @everyone send messages again.
await unlock_channel(channel=None, reason=None)set_slowmode#
Sets how many seconds each member must wait between messages.
await set_slowmode(seconds, channel=None, reason=None)seconds goes from 0 (off) to 21600 (6 hours). Bigger numbers are cut to 6 hours.
await set_slowmode(10)
set_content("Slowmode is on: one message every 10 seconds.")PermissionOverwrites#
Sets who can see or use a new channel. Pass it as permission_overwrites= to create_text_channel, create_voice_channel, create_category, create_thread or update_channel.
perms = PermissionOverwrites()
perms.add_role(role, allow=..., deny=...)
perms.add_member(member, allow=..., deny=...)
perms.remove(role_or_member)allow and deny take a permissions value from get_permission(...).
Example: a private ticket channel
perms = PermissionOverwrites()
# @everyone has the same ID as the server
perms.add_role(server.id, deny=get_permission("view_channel"))
perms.add_member(user, allow=get_permission("view_channel", "send_messages"))
perms.add_role(get_role("Staff"), allow=get_permission("view_channel", "send_messages"))
ticket = create_text_channel(f"ticket-{user.username}", permission_overwrites=perms)See the ticket system guide for the full version.