Someone know how to make the bot close the modmail? Like the member start spamming on the bot dms and you want to like block him
here is my modmail code
#client.event
async def on_message(message):
channel = client.get_channel(909853337510371449)
if message.author.id == client.user.id:
return
if message.author != message.author.bot:
if not message.guild:
await channel.send(f"[{message.author.mention}] {message.content}")
await client.process_commands(message)
Related
I added the bot status and after that the
Commands don't work. Added a answerers answer but it still no work ( help works not but not hello ;-;)
import discord
from KeepAlive import keep_alive
client=discord.Client()
#client.event
async def on_ready():
await client.change_presence(status=discord.Status.online,activity=discord.Game('Hey There! Do €help to start!'))
print('We have logged in as {0.user}'.format(discord.Client))
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
if message.content.startswith('$help'):
await message.channel.send('no help here!')
await bot.process_commands(message)
keep_alive()
client.run('wont say token :)')
If you are talking about commands and not "commands" that you run with on_message then you have to add await client.process_commands(message) (check this issue in documentation). If your on_message event is not working then it's probably only because of missing _ in on_message event.
#client.event
async def on_message(message): # your forgot "_"
if message.author == client.user: # discord.Client won't work. Use client.user instead
return
if message.content.startswith('$hello'):
await message.channel.send('Hello!')
if message.content.startswith('$help'):
await message.channel.send('no help here!')
await client.process_commands(message) # add this line at the end of your on_message event
the problem is your message function, it has async def onmessage(message): but the correct one is:
#client.event
async def on_message(message):
And I recommend defining the prefix and then separating it from the message so you don't have to keep typing $ in every if, and save the elements written after the command for future functions:
PREFIX = "$"
#client.event
async def on_message(message):
msg = message.content[1:].split(' ')
command = msg[0]
if command == "hello":
await message.channel.send('Hello!')
I'm trying to detect a message from a specific user (me), delete it and send the same message again.
#client.event
async def on_message(message):
if message.author.id == 881583268569436200:
await message.delete(message)
await client.process_commands(message)
I don't know what I'm doing wrong. Please help
You don't have to use await message.delete(message) you already got the message after await statement. Just use await message.delete().
#client.event
async def on_message(message):
if message.author.id == 881583268569436200:
msg = message.content
await message.delete()
await message.channel.send(msg)
await client.process_commands(message)
#bot.event
async def on_message(message):
if '!' in message.content:
return
if message.content.startswith(muti):
await asyncio.sleep(3)
await message.delete()
else:
await message.delete()
await message.channel.send(muti)
if message.author.bot:
return
I am trying to create an exception where my bot will not delete another bot's message, but I don't know how to do it. I tried to use if message.author.(the other bot's id variable) but then I don't know how to set that variable up. The message.author.bot is for my bot to ignore its own messages.
Using member.bot which returns if the member is a bot documentation.
#bot.event
async def on_message(message):
if message.author.bot:
return
if '!' in message.content:
return
if message.content.startswith(muti):
await asyncio.sleep(3)
await message.delete()
else:
await message.delete()
await message.channel.send(muti)
if message.author.bot:
return
This will not execute any of the code below if the message was sent by a bot.
from discord.ext import commands
load_dotenv("token.env")
token = os.getenv("Token")
bot = commans.Bot(command_prefix="!")
#bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith("!"):
await bot.process_commands(message)
return
else:
author = message.author
await message.channel.send(message.content)
How can i change the code in line 15 to send the message to "author"?
You can use Member.create_dm() for this. You can modify your code as follows:
from discord.ext import commands
load_dotenv("token.env")
token = os.getenv("Token")
bot = commands.Bot(command_prefix="!")
#bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith("!"):
await bot.process_commands(message)
return
else:
c = await message.author.create_dm()
await c.send(message.content)
You also misspelt commands in bot = commands.Bot(... :)
You could use await ctx.author.send() so that whoever runs the command would get it sent in there dms
from discord.ext import commands
load_dotenv("token.env")
token = os.getenv("Token")
bot = commands.Bot(command_prefix="!")
#bot.event
async def on_message(message):
if message.author == bot.user:
return
if message.content.startswith("!"):
await bot.process_commands(message)
return
else:
author = message.author
await ctx.author.send(message.content)
import discord
import asyncio
client = discord.Client()
#client.event
async def on_ready():
print ("I’m Now Online")
#client.event
async def on_message(message):
if message.author == client.user:
return
elif message.content.startswith("deletethis"):
I’m wonder how I could be able to add to this to delete the above command when the author of the message sends the command above.
May someone help create one? I’ve tried my self by brain and didn’t find anything online so I’m looking for some help maybe.
for async just do
await client.delete_message(message)
otherwise for rewrite just do
await message.delete()
Finished code:
#client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith("deletethis"):
await asyncio.sleep(1)
await message.delete()