I'm looking to create a script that forward message from discord to telegram. I made the example below but it's not working
client2 = TelegramClient(phone, api_id, api_hash, flood_sleep_threshold=3)
client2.connect()
#client.event
async def on_message(message):
await client2.send_message("username", message=message.content)
Is there is any way to send a telegram message from another event.
Related
I'm making a bot for a discord server. He doesn't respond to messages, what should I do?
import discord
from discord.ext import commands
client = commands.Bot( command_prefix= "!")
#client.event
async def on_ready():
print('Bot active')
async def hello(ctx):
author = ctx.message.author
await ctx.send('Привет, как поживаешь')
#client.command()
async def send_a( ctx ):
await ctx.author.send("Привет")
token = "here my id"
client.run(token)
He must send messages to the chat, as well as private messages to the server participants
Im making a discord bot in python so that it can auto mod, and it works, but only if I ping the bot
For example
Saying [insert profanity here] wouldn't auto delete the message
But, saying [insert profanity here + #bot] would delete the message
How can I get it to work without any pings?
Source Code:
`import discord
token = "[insert discord token here]"
block_words = ["(List of profanity here)"]
intents = discord.Intents.default()
client = discord.Client(intents=intents)
#client.event
async def on_ready():
print(f"Bot logged in as {client.user}")
#client.event
async def on_message(msg):
if msg.author != client.user:
for text in block_words:
if str(msg.content.lower()):
await msg.delete()
return
print("not deleting")
client.run(token)
I wasn't able to think of any ideas for what to do`
I want to make that when a user join to the server where this bot is located, the bot should send him a greeting message in the dm. But when connecting, the bot does not send a message. No errors are displayed. How can I fix this? My code:
#client.event
async def on_member_join():
await member.send("Welcome!")
#client.eevent
async def on_member_join(member):
await member.send("Welcome!")
you need to have an arguement in the function!
Also you need to enable intents in your bot
client = discord.Client(command_prefix="!", intents=discord.Intents.all(),case_insensitive=True)
you also need to enable all intents in the discord Developer portal
I just started with discord.py and found out that on_member_join and on_member_remove don't work for me. Keep in mind that on_ready function works perfectly fine.
import discord
from discord.ext import commands
bot = commands.Bot(command_prefix = "!")
#bot.event
async def on_ready():
print("""Bot ready""")
#bot.event
async def on_member_join(member):
channel = bot.get_channel(767370104814960640)
await channel.send(f"{member} has joined the server")
#bot.event
async def on_member_remove(member):
channel = bot.get_channel(766620766237753345)
await channel.send(f"{member} has left the server")
bot.run("my token")
So did I make a mistake with my code or something else went wrong?
discord.py 1.5.0 now supports discord API's Privileged Gateway Intents. In order to be able to exploit server data, you need to:
Enable Presence Intent and Server Members Intent in your discord application:
https://i.stack.imgur.com/h6IE4.png
Use discord.Intents at the beginning of your code:
intents = discord.Intents.all()
#If you use commands.Bot()
bot = commands.Bot(command_prefix="!", intents=intents)
#If you use discord.Client()
client = discord.Client(intents=intents)
I am currently learning how to make a discord bot using python. But I am stuck at the beginning. My bot is not responding.
It is NOT showing an error. Also in the discord server the bot is showing online.
But when I run guild.member_count it shows the correct number of members. But when I try to get the information of the members by guild.members, it just shows my bot in the list.
Moreover If I try to send message by await member.create_dm() in on_member_join(), it don't send any message.
Also I gave the bot administrator permission to see if its some problem with permissions but still the same.
Below is my code :
import discord
TOKEN = <MyToken> # I have replaced this with my actual token in the actual code
client = discord.Client()
#client.event
async def on_ready():
guild = discord.utils.get(client.guilds, name=GUILD)
print(
f"{client.user} is connected to Discord!\n"
f"Connected to {guild.name} (id: {guild.id}, members-count: {guild.member_count})"
)
members = '\n - '.join([member.name for member in guild.members])
print(f'Guild Members:\n - {members}')
#client.event
async def on_member_join(member):
await member.create_dm()
await member.dm_channel.send(
f"Hello {member.name}, Welcome to the test discord server!"
)
print(f"Welcomed {member.name}.\n")
client.run(TOKEN)
it just shows my bot in the list.
See this page on Gateway Intents
it don't send any message
Try just using
await member.send(...)