First of all I am sorry if I'm doing something wrong. This is my first question. I am currently trying to create a Discord Bot using Python.
Edit: Though the answer of one person helped me a lot, my question remains, because I still have the "await coro" exception and another one was thrown after I corrected the old mistake. I've updated the code and the exceptions. Thanks for your help!
When I'm trying to send an embed when the bot joins the server, I get two exceptions. Since I don't have 50 servers, I replaced the on_member_join(self) with a simple function call when something is written in a channel:
Here's the code of the two functions trying to send an embed:
import discord
from discord.utils import get
from discord.ext import commands
Bot_prefix = "<" #Later used before every command
class MyClient(discord.Client):
async def Joining_Server(ctx, self):
#Get channel by name:
channel = get(ctx.guild.text_channels, name="Channel Name")
#Get channel by ID:
channels_Ids = get(ctx.guild.text_channels, id=discord.channel_id)
embed = discord.Embed(title="Thanks for adding me!", description="Try")
fields = [("Prefix", "My prefix is <. Just write it in front of every command!", True),
("Changing prefix", "Wanna change my prefix? Just write \"<change_prefix\" and the prefix you want, such as: \"<change_prefix !\"", True),
("Commands", "For a list of the most important commands type \"<help\"", False),
("Help", "For more help, type \"<help_All\" or visit:", True)]
for channels in self.channel_Ids:
if(commands.has_permissions(write=True)):
channel_verified = channels.id
await ctx.channel_verified.send(embed)
async def on_message(message, self, ctx):
if message.author == client.user:
return
if message.content == "test":
await MyClient.Joining_Server(ctx, self)
Thank you for helping me! Again: I'm sorry if I'm doing something wrong, it's my first question. Please ask if you need something. Feedback would also be very helpful.
I think you simply want to compare the content of the message to the "test"
string
if message.author == client.user:
return
if message.content == "test":
await MyClient.Joining_Server()