im trying to send a message in specific channel...i know how to specify channel normally but im getting very confused in cogs im really not able to understand how to do so....any help is appreciated:)
@commands.Cog.listener()
async def on_ready(ctx, channel:discord.Channel=None):
channel = '785465306470547457'
role = discord.utils.get(user.server.roles, name="Orange")
message = await ctx.send_message(channel, "React to me!")
while True:
reaction = await ctx.wait_for_reaction(emoji="🟠", message=message)
await ctx.add_roles(reaction.message.author, role)
ERROR
discord.ext.commands.errors.ExtensionFailed: Extension 'cogs.rolesystem' raised an error: AttributeError: module 'discord' has no attribute 'Channel'
staticmethod
or classmethod
) functions always take self
as the first argumenton_ready
doesn't take any arguments discord.TextChannel
not discord.Channel
also use this only in commandsabc.Messageable
object not string
user
, also server
has been renamed to guild
in version 1.0.0
ctx.send
not ctx.send_message
bot.wait_for
not ctx.wait_for_reaction
Also, what's the while loop suppose to do?
@commands.Cog.listener()
async def on_ready(self):
"""This will wait for someone to react with `🟠`
and add him a role
Note: This will wait only for one reaction"""
channel_id = 785465306470547457
# Getting the channel
channel = self.bot.get_channel(channel_id)
# Getting the role
role = discord.utils.get(channel.guild.roles, name='Orange')
# Sending the message
message = await channel.send('React to me')
def check(reaction, user):
"""Checks if the reaction message is the one sent before
and if the reaction is `🟠`"""
return reaction.message == message and str(reaction) == '🟠'
# Waiting for the reaction
reaction, user = await self.bot.wait_for('reaction_add', check=check)
# Adding the role
await user.add_roles(role)
Note: This code will not work unless you enable default intents and intents.members
here's an introduction to intents.
Please read the documentation , it's really helpful and learn more python and OOP before diving into discord.py
.
Also, from the code, I suppose you want to send a static message, and when someone reacts, add him a role, use the on_raw_reaction_add
event for that
Reference:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.