forked from Pycord-Development/pycord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
202 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,33 @@ | ||
# This example requires the `message_content` privileged intent for access to message content. | ||
|
||
import discord | ||
|
||
intents = discord.Intents.default() | ||
intents.message_content = True # < This may give you `read-only` warning, just ignore it. | ||
# This intent requires "Message Content Intent" to be enabled at https://discord.com/developers | ||
|
||
|
||
class MyClient(discord.Client): | ||
async def on_ready(self): | ||
print(f"Logged in as {self.user} (ID: {self.user.id})") | ||
print("------") | ||
bot = discord.Bot(intents=intents) | ||
|
||
async def on_message(self, message: discord.Message): | ||
if message.content.startswith("!deleteme"): | ||
msg = await message.channel.send("I will delete myself now...") | ||
await msg.delete() | ||
|
||
# This also works: | ||
await message.channel.send("Goodbye in 3 seconds...", delete_after=3.0) | ||
@bot.event | ||
async def on_ready(): | ||
print('Ready!') | ||
|
||
async def on_message_delete(self, message: discord.Message): | ||
msg = f"{message.author} has deleted the message: {message.content}" | ||
await message.channel.send(msg) | ||
|
||
@bot.event | ||
async def on_message(message: discord.Message): | ||
if message.content.startswith("!deleteme"): | ||
msg = await message.channel.send("I will delete myself now...") | ||
await msg.delete() | ||
|
||
intents = discord.Intents.default() | ||
intents.message_content = True | ||
# This also works: | ||
await message.channel.send("Goodbye in 3 seconds...", delete_after=3.0) | ||
|
||
|
||
@bot.event | ||
async def on_message_delete(message: discord.Message): | ||
msg = f"{message.author} has deleted the message: {message.content}" | ||
await message.channel.send(msg) | ||
|
||
|
||
bot.run("TOKEN") | ||
|
||
client = MyClient(intents=intents) | ||
client.run("TOKEN") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,31 @@ | ||
# This example requires the `message_content` privileged intent for access to message content. | ||
|
||
import discord | ||
import asyncio | ||
|
||
import discord | ||
intents = discord.Intents.default() | ||
intents.message_content = True # < This may give you `read-only` warning, just ignore it. | ||
# This intent requires "Message Content Intent" to be enabled at https://discord.com/developers | ||
|
||
|
||
class MyClient(discord.Client): | ||
async def on_ready(self): | ||
print(f"Logged in as {self.user} (ID: {self.user.id})") | ||
print("------") | ||
bot = discord.Bot(intents=intents) | ||
|
||
async def on_message(self, message: discord.Message): | ||
if message.content.startswith("!editme"): | ||
msg = await message.channel.send("10") | ||
await asyncio.sleep(3.0) | ||
await msg.edit(content="40") | ||
|
||
async def on_message_edit(self, before: discord.Message, after: discord.Message): | ||
msg = f"**{before.author}** edited their message:\n{before.content} -> {after.content}" | ||
await before.channel.send(msg) | ||
@bot.event | ||
async def on_ready(): | ||
print('Ready!') | ||
|
||
|
||
intents = discord.Intents.default() | ||
intents.message_content = True | ||
@bot.event | ||
async def on_message(message: discord.Message): | ||
if message.content.startswith("!editme"): | ||
msg = await message.channel.send("10") | ||
await asyncio.sleep(3.0) | ||
await msg.edit(content="40") | ||
|
||
|
||
@bot.event | ||
async def on_message_edit(before: discord.Message, after: discord.Message): | ||
msg = f"**{before.author}** edited their message:\n{before.content} -> {after.content}" | ||
await before.channel.send(msg) | ||
|
||
|
||
client = MyClient(intents=intents) | ||
client.run("TOKEN") | ||
bot.run("TOKEN") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,94 @@ | ||
# This example requires the 'members' privileged intent for access to .get_member. | ||
|
||
import discord | ||
|
||
|
||
class MyClient(discord.Client): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
self.role_message_id = 0 # ID of the message that can be reacted to for adding/removing a role. | ||
self.emoji_to_role = { | ||
discord.PartialEmoji(name="🔴"): 0, # ID of the role associated with unicode emoji '🔴'. | ||
discord.PartialEmoji(name="🟡"): 0, # ID of the role associated with unicode emoji '🟡'. | ||
discord.PartialEmoji(name="green", id=0): 0, # ID of the role associated with a partial emoji's ID. | ||
} | ||
|
||
async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent): | ||
"""Gives a role based on a reaction emoji.""" | ||
# Make sure that the message the user is reacting to is the one we care about. | ||
if payload.message_id != self.role_message_id: | ||
return | ||
|
||
guild = self.get_guild(payload.guild_id) | ||
if guild is None: | ||
# Make sure we're still in the guild, and it's cached. | ||
return | ||
|
||
try: | ||
role_id = self.emoji_to_role[payload.emoji] | ||
except KeyError: | ||
# If the emoji isn't the one we care about then exit as well. | ||
return | ||
|
||
role = guild.get_role(role_id) | ||
if role is None: | ||
# Make sure the role still exists and is valid. | ||
return | ||
|
||
try: | ||
# Finally, add the role. | ||
await payload.member.add_roles(role) | ||
except discord.HTTPException: | ||
# If we want to do something in case of errors we'd do it here. | ||
pass | ||
|
||
async def on_raw_reaction_remove(self, payload: discord.RawReactionActionEvent): | ||
"""Removes a role based on a reaction emoji.""" | ||
# Make sure that the message the user is reacting to is the one we care about. | ||
if payload.message_id != self.role_message_id: | ||
return | ||
|
||
guild = self.get_guild(payload.guild_id) | ||
if guild is None: | ||
# Make sure we're still in the guild, and it's cached. | ||
return | ||
|
||
try: | ||
role_id = self.emoji_to_role[payload.emoji] | ||
except KeyError: | ||
# If the emoji isn't the one we care about then exit as well. | ||
return | ||
|
||
role = guild.get_role(role_id) | ||
if role is None: | ||
# Make sure the role still exists and is valid. | ||
return | ||
|
||
# The payload for `on_raw_reaction_remove` does not provide `.member` | ||
# so we must get the member ourselves from the payload's `.user_id`. | ||
member = guild.get_member(payload.user_id) | ||
if member is None: | ||
# Make sure the member still exists and is valid. | ||
return | ||
|
||
try: | ||
# Finally, remove the role. | ||
await member.remove_roles(role) | ||
except discord.HTTPException: | ||
# If we want to do something in case of errors we'd do it here. | ||
pass | ||
|
||
import asyncio | ||
|
||
intents = discord.Intents.default() | ||
intents.members = True | ||
|
||
client = MyClient(intents=intents) | ||
client.run("TOKEN") | ||
intents.members = True # < This may give you `read-only` warning, just ignore it. | ||
# This intent requires "Server Members Intent" to be enabled at https://discord.com/developers | ||
|
||
|
||
bot = discord.Bot(intents=intents) | ||
|
||
role_message_id = 0 # ID of the message that can be reacted to for adding/removing a role. | ||
|
||
emoji_to_role = { | ||
discord.PartialEmoji(name="🔴"): 0, # ID of the role associated with unicode emoji '🔴'. | ||
discord.PartialEmoji(name="🟡"): 0, # ID of the role associated with unicode emoji '🟡'. | ||
discord.PartialEmoji(name="green", id=0): 0, # ID of the role associated with a partial emoji's ID. | ||
} | ||
|
||
|
||
@bot.event | ||
async def on_ready(): | ||
print('Ready!') | ||
|
||
|
||
@bot.event | ||
async def on_raw_reaction_add(payload: discord.RawReactionActionEvent): | ||
"""Gives a role based on a reaction emoji.""" | ||
# Make sure that the message the user is reacting to is the one we care about. | ||
if payload.message_id != role_message_id: | ||
return | ||
|
||
guild = bot.get_guild(payload.guild_id) | ||
if guild is None: | ||
# Make sure we're still in the guild, and it's cached. | ||
return | ||
|
||
try: | ||
role_id = emoji_to_role[payload.emoji] | ||
except KeyError: | ||
# If the emoji isn't the one we care about then exit as well. | ||
return | ||
|
||
role = guild.get_role(role_id) | ||
if role is None: | ||
# Make sure the role still exists and is valid. | ||
return | ||
|
||
try: | ||
# Finally, add the role. | ||
await payload.member.add_roles(role) | ||
except discord.HTTPException: | ||
# If we want to do something in case of errors we'd do it here. | ||
pass | ||
|
||
|
||
@bot.event | ||
async def on_raw_reaction_remove(payload: discord.RawReactionActionEvent): | ||
"""Removes a role based on a reaction emoji.""" | ||
# Make sure that the message the user is reacting to is the one we care about. | ||
if payload.message_id != role_message_id: | ||
return | ||
|
||
guild = bot.get_guild(payload.guild_id) | ||
if guild is None: | ||
# Make sure we're still in the guild, and it's cached. | ||
return | ||
|
||
try: | ||
role_id = emoji_to_role[payload.emoji] | ||
except KeyError: | ||
# If the emoji isn't the one we care about then exit as well. | ||
return | ||
|
||
role = guild.get_role(role_id) | ||
if role is None: | ||
# Make sure the role still exists and is valid. | ||
return | ||
|
||
# The payload for `on_raw_reaction_remove` does not provide `.member` | ||
# so we must get the member ourselves from the payload's `.user_id`. | ||
member = guild.get_member(payload.user_id) | ||
if member is None: | ||
# Make sure the member still exists and is valid. | ||
return | ||
|
||
try: | ||
# Finally, remove the role. | ||
await member.remove_roles(role) | ||
except discord.HTTPException: | ||
# If we want to do something in case of errors we'd do it here. | ||
pass | ||
|
||
|
||
bot.run("TOKEN") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,26 @@ | ||
# This example requires the `message_content` privileged intent for access to message content. | ||
|
||
import discord | ||
|
||
intents = discord.Intents.default() | ||
intents.message_content = True # < This may give you `read-only` warning, just ignore it. | ||
# This intent requires "Message Content Intent" to be enabled at https://discord.com/developers | ||
|
||
class MyClient(discord.Client): | ||
async def on_ready(self): | ||
print(f"Logged in as {self.user} (ID: {self.user.id})") | ||
print("------") | ||
|
||
async def on_message(self, message: discord.Message): | ||
# Make sure we won't be replying to ourselves. | ||
if message.author.id == self.user.id: | ||
return | ||
bot = discord.Bot(intents=intents) | ||
|
||
if message.content.startswith("!hello"): | ||
await message.reply("Hello!", mention_author=True) | ||
|
||
@bot.event | ||
async def on_ready(): | ||
print('Ready!') | ||
|
||
|
||
@bot.event | ||
async def on_message(message: discord.Message): | ||
# Make sure we won't be replying to ourselves. | ||
if message.author.id == bot.user.id: | ||
return | ||
|
||
if message.content.startswith("!hello"): | ||
await message.reply("Hello!", mention_author=True) | ||
|
||
intents = discord.Intents.default() | ||
intents.message_content = True | ||
|
||
client = MyClient(intents=intents) | ||
client.run("TOKEN") | ||
bot.run("TOKEN") |
Oops, something went wrong.