Discord Bot does not respond anymore - discord.py
Long question due to the code, but why does my bot not respond anymore? It's custom made for a friend and has been working for the past week or so, but now just does not respond. No errors are raised either. The only time it sends a message is when League Membership isn't in member roles and it sends the correct message. Otherwise, the bot does not respond.
import discord
from discord.ext import commands
from keep_alive import keep_alive
import asyncio
import os
import pytz
from datetime import datetime
timestamp = datetime.now(pytz.timezone('EST'))
intents = discord.Intents.default()
intents.members=True
bot = commands.Bot(command_prefix='-', intents=intents)
#bot.event
async def on_member_join(member):
guild = bot.get_guild(801206329049612288)
membercount = len([m for m in guild.members if not m.bot])
embedwelcome = discord.Embed(title="Your KFG Future Awaits You.", description=None, color=discord.Color.teal())
embedwelcome.add_field(name="Things to do:", value=f"•Get Signed or claim a Franchise!\n•Make friends in the community!\n•Collect Rings\n•Make your way to the Super Bowl and win it all!\nWhat are you waiting for? Hurry up and get started!\n (You were member #{membercount}.)", inline=True)
await member.send(embed=embedwelcome)
print(f"{timestamp} - {member}")
#bot.command()
async def membercount(ctx):
guild = bot.get_guild(801206329049612288)
membercount = len([m for m in guild.members if not m.bot])
await ctx.send(f'KFG has {membercount} members.')
print(f"{timestamp} - {ctx.author}")
#bot.command()
async def welcomemessage(ctx):
guild = bot.get_guild(801206329049612288)
membercount = len([m for m in guild.members if not m.bot])
embedwelcome = discord.Embed(title="Your KFG Future Awaits You.", description=None, color=discord.Color.teal())
embedwelcome.add_field(name="Things to do:", value=f"•Get Signed or claim a Franchise!\n•Make friends in the community!\n•Collect Rings\n•Make your way to the Super Bowl and win it all!\nWhat are you waiting for? Hurry up and get started!\n (You were member #{membercount}.)", inline=True)
await ctx.send(embed=embedwelcome)
print(f"{timestamp} - {ctx.author}")
#bot.event
async def on_ready():
print ("I'm online.")
await bot.change_presence(activity=discord.Game(name="KFG on top!"))
#bot.event
async def on_message(message, user:discord.Member=None):
if "sign" in message.content:
signer=message.author
signee=message.mentions[0].mention
signeeid=message.mentions[0].id
server=bot.get_guild(801206329049612288)
teamsidslist=[801217912689393714, 801218094814986300, 801224104086208513, 801224243115196426, 801218409878519849, 801222227479625758, 801217334395011113, 801224558589378570, 801222379682005035, 801224701128343662, 801222478646476820, 801222668128747540, 801224835032285225, 801225075231031316, 801225211306967080, 801225374369185793, 801225554199576627, 801225700283121674, 801222743030104104, 801225798408732692, 801222852132995132, 801225991242514473, 801222923746148392, 801223092298186782, 801226082207924244, 801223311081996288, 801226241948647496, 801223486973542451, 801223635858882562, 801223809340276745, 801226427890139137, 801223952344416337]
teamnames=['Arizona Cardinals', 'Atlanta Falcons', 'Baltimore Ravens', 'Buffalo Bills', 'Carolina Panthers', 'Chicago Bears', 'Cincinnati Bengals', 'Cleveland Browns', 'Dallas Cowboys', 'Denver Broncos', 'Detroit Lions', 'Green Bay Packers', 'Houston Texans', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Miami Dolphins', 'Los Angeles Chargers', 'Kansas City Chiefs', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Las Vegas Raiders', 'Los Angeles Chargers', 'Los Angeles Rams', 'Miami Dolphins', 'Minnesota Vikings', 'New England Patriots','New Orleans Saints', 'New York Giants', 'New York Jets', 'Philidelphia Eagles', 'Pittsburgh Steelers', 'San Fransisco 49ers', 'Seattle Seahawks', 'Tampa Bay Buccaneers', 'Tennesse Titans', 'Washington Football Team']
teamemojis=['Arizona_Cardinals', 'Atlanta_Falcons', 'Baltimore_Ravens', 'Buffalo_Bills', 'Carolina_Panthers', 'Chicago_Bears', 'Cincinnati_Bengals', 'Cleveland_Browns', 'Dallas_Cowboys', 'Denver_Broncos', 'Detroit_Lions', 'Green_Bay_Packers', 'Houston_Texans', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Miami_Dolphins', 'Los_Angeles_Chargers', 'Kansas_City_Chiefs', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Las_Vegas_Raiders', 'Los_Angeles_Chargers', 'Los_Angeles_Rams', 'Miami_Dolphins', 'Minnesota_Vikings', 'New_England_Patriots', 'New_Orleans_Saints', 'New_York_Giants', 'New_York_Jets', 'Philidelphia_Eagles', 'Pittsburgh_Steelers', 'San_Francisco_49ers', 'Seattle_Seahawks', 'Tampa_Bay_Buccaneers', 'Tennessee_Titans', 'Washington_Football_Team']
FO = discord.utils.get(message.author.guild.roles, id=801257262240235530)
GM = discord.utils.get(message.author.guild.roles, id=801257315620749362)
HC = discord.utils.get(message.author.guild.roles, id=801257358751694848)
AC = discord.utils.get(message.author.guild.roles, id=801257421334904872)
FA = discord.utils.get(message.author.guild.roles, id=801255786062807090)
Suspended = discord.utils.get(message.author.guild.roles, id=805818648802361426)
roster=[]
agency=[]
teams=[]
for rolesids in message.author.roles:
if rolesids.id in teamsidslist:
teams.append(rolesids.id)
step2=str(teams)
step3=step2.replace("[","")
step4=step3.replace("]","")
print(step4)
step5=teamsidslist.index(int(step4))
print(step5)
emote=discord.utils.get(server.emojis,name=teamemojis[step5])
teamname=teamnames[step5]
team = discord.utils.get(message.author.guild.roles,id=int(step4))
for agents in server.members:
if FA in agents.roles:
agency.append(agents.id)
if signeeid not in agency:
embedno = discord.Embed(title="Transaction Failed!", description=None, color=discord.Color.red())
embedno.add_field(name="This Transaction Couldn't Be Completed.", value="This player is signed already! Have them demand from their team or get released.")
await message.channel.send(embed=embedno)
elif [FO, GM, HC, AC] in message.author.roles:
for guys in server.members:
if guys.id==signeeid:
await guys.add_roles(team)
await guys.remove_roles(FA)
if Suspended in guys.roles:
await message.channel.send("This player is signable, but is ineligible as they are suspended.")
roster.append(guys)
roster_size=str(len(roster))
SignEmbed= discord.Embed(title="KFG Transactions", description=None, color=discord.Color.green())
SignEmbed.add_field(name='Successful Transaction.', value=signee+" has been signed to the "+str(emote)+" "+teamname+"!")
SignEmbed.add_field(name="Roster Size is now ", value=roster_size+'/20', inline=True)
await message.channel.send(embed=SignEmbed)
bot.remove_command('help')
#bot.event
async def on_message3(message, user:discord.Member=None):
if "I demand" in message.content:
signer=message.author
signee=message.mentions[0].mention
signeeid=message.mentions[0].id
server=bot.get_guild(801206329049612288)
teamsidslist=[801217912689393714, 801218094814986300, 801224104086208513, 801224243115196426, 801218409878519849, 801222227479625758, 801217334395011113, 801224558589378570, 801222379682005035, 801224701128343662, 801222478646476820, 801222668128747540, 801224835032285225, 801225075231031316, 801225211306967080, 801225374369185793, 801225554199576627, 801225700283121674, 801222743030104104, 801225798408732692, 801222852132995132, 801225991242514473, 801222923746148392, 801223092298186782, 801226082207924244, 801223311081996288, 801226241948647496, 801223486973542451, 801223635858882562, 801223809340276745, 801226427890139137, 801223952344416337]
teamnames=['Arizona Cardinals', 'Atlanta Falcons', 'Baltimore Ravens', 'Buffalo Bills', 'Carolina Panthers', 'Chicago Bears', 'Cincinnati Bengals', 'Cleveland Browns', 'Dallas Cowboys', 'Denver Broncos', 'Detroit Lions', 'Green Bay Packers', 'Houston Texans', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Miami Dolphins', 'Los Angeles Chargers', 'Kansas City Chiefs', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Las Vegas Raiders', 'Los Angeles Chargers', 'Los Angeles Rams', 'Miami Dolphins', 'Minnesota Vikings', 'New England Patriots','New Orleans Saints', 'New York Giants', 'New York Jets', 'Philidelphia Eagles', 'Pittsburgh Steelers', 'San Fransisco 49ers', 'Seattle Seahawks', 'Tampa Bay Buccaneers', 'Tennesse Titans', 'Washington Football Team']
teamemojis=['Arizona_Cardinals', 'Atlanta_Falcons', 'Baltimore_Ravens', 'Buffalo_Bills', 'Carolina_Panthers', 'Chicago_Bears', 'Cincinnati_Bengals', 'Cleveland_Browns', 'Dallas_Cowboys', 'Denver_Broncos', 'Detroit_Lions', 'Green_Bay_Packers', 'Houston_Texans', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Miami_Dolphins', 'Los_Angeles_Chargers', 'Kansas_City_Chiefs', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Las_Vegas_Raiders', 'Los_Angeles_Chargers', 'Los_Angeles_Rams', 'Miami_Dolphins', 'Minnesota_Vikings', 'New_England_Patriots', 'New_Orleans_Saints', 'New_York_Giants', 'New_York_Jets', 'Philidelphia_Eagles', 'Pittsburgh_Steelers', 'San_Francisco_49ers', 'Seattle_Seahawks', 'Tampa_Bay_Buccaneers', 'Tennessee_Titans', 'Washington_Football_Team']
FO = discord.utils.get(message.author.guild.roles, id=801257262240235530)
GM = discord.utils.get(message.author.guild.roles, id=801257315620749362)
HC = discord.utils.get(message.author.guild.roles, id=801257358751694848)
AC = discord.utils.get(message.author.guild.roles, id=801257421334904872)
FA = discord.utils.get(message.author.guild.roles, id=801255786062807090)
roster=[]
teams=[]
agency=[]
for rolesids in message.author.roles:
if rolesids.id in teamsidslist:
teams.append(rolesids.id)
step2=str(teams)
step3=step2.replace("[","")
step4=step3.replace("]","")
print(step4)
step5=teamsidslist.index(int(step4))
print(step5)
emote=discord.utils.get(server.emojis,name=teamemojis[step5])
teamname=teamnames[step5]
team = discord.utils.get(message.author.guild.roles,id=int(step4))
if [teams] in message.author.roles:
for guys in server.members:
if guys.id==signeeid:
await guys.add_roles(FA)
await guys.remove_roles(team)
if signeeid in agency:
await message.channel.send('You are not signed and cannot demand!')
roster.append(guys)
roster_size=str(len(roster))
SignEmbed= discord.Embed(title="KFG Transactions", description=None, color=discord.Color.green())
SignEmbed.add_field(name='Successful Transaction.', value=signee+" has demanded from the "+str(emote)+" "+teamname+"!")
SignEmbed.add_field(name=f"{str(emote)} {teamname}Roster Size is now ", value=roster_size+'/20', inline=True)
await message.channel.send(embed=SignEmbed)
#bot.event
async def on_message2(message, user:discord.Member=None):
if "release" in message.content:
signer=message.author
signee=message.mentions[0].mention
signeeid=message.mentions[0].id74
server=bot.get_guild(801206329049612288)
teamsidslist=[801217912689393714, 801218094814986300, 801224104086208513, 801224243115196426, 801218409878519849, 801222227479625758, 801217334395011113, 801224558589378570, 801222379682005035, 801224701128343662, 801222478646476820, 801222668128747540, 801224835032285225, 801225075231031316, 801225211306967080, 801225374369185793, 801225554199576627, 801225700283121674, 801222743030104104, 801225798408732692, 801222852132995132, 801225991242514473, 801222923746148392, 801223092298186782, 801226082207924244, 801223311081996288, 801226241948647496, 801223486973542451, 801223635858882562, 801223809340276745, 801226427890139137, 801223952344416337]
teamnames=['Arizona Cardinals', 'Atlanta Falcons', 'Baltimore Ravens', 'Buffalo Bills', 'Carolina Panthers', 'Chicago Bears', 'Cincinnati Bengals', 'Cleveland Browns', 'Dallas Cowboys', 'Denver Broncos', 'Detroit Lions', 'Green Bay Packers', 'Houston Texans', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Miami Dolphins', 'Los Angeles Chargers', 'Kansas City Chiefs', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Las Vegas Raiders', 'Los Angeles Chargers', 'Los Angeles Rams', 'Miami Dolphins', 'Minnesota Vikings', 'New England Patriots','New Orleans Saints', 'New York Giants', 'New York Jets', 'Philidelphia Eagles', 'Pittsburgh Steelers', 'San Fransisco 49ers', 'Seattle Seahawks', 'Tampa Bay Buccaneers', 'Tennesse Titans', 'Washington Football Team']
teamemojis=['Arizona_Cardinals', 'Atlanta_Falcons', 'Baltimore_Ravens', 'Buffalo_Bills', 'Carolina_Panthers', 'Chicago_Bears', 'Cincinnati_Bengals', 'Cleveland_Browns', 'Dallas_Cowboys', 'Denver_Broncos', 'Detroit_Lions', 'Green_Bay_Packers', 'Houston_Texans', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Miami_Dolphins', 'Los_Angeles_Chargers', 'Kansas_City_Chiefs', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Las_Vegas_Raiders', 'Los_Angeles_Chargers', 'Los_Angeles_Rams', 'Miami_Dolphins', 'Minnesota_Vikings', 'New_England_Patriots', 'New_Orleans_Saints', 'New_York_Giants', 'New_York_Jets', 'Philidelphia_Eagles', 'Pittsburgh_Steelers', 'San_Francisco_49ers', 'Seattle_Seahawks', 'Tampa_Bay_Buccaneers', 'Tennessee_Titans', 'Washington_Football_Team']
FO = discord.utils.get(message.author.guild.roles, id=801257262240235530)
GM = discord.utils.get(message.author.guild.roles, id=801257315620749362)
HC = discord.utils.get(message.author.guild.roles, id=801257358751694848)
AC = discord.utils.get(message.author.guild.roles, id=801257421334904872)
FA = discord.utils.get(message.author.guild.roles, id=801255786062807090)
roster=[]
teams=[]
for rolesids in message.author.roles:
if rolesids.id in teamsidslist:
teams.append(rolesids.id)
step2=str(teams)
step3=step2.replace("[","")
step4=step3.replace("]","")
print(step4)
step5=teamsidslist.index(int(step4))
print(step5)
emote=discord.utils.get(server.emojis,name=teamemojis[step5])
teamname=teamnames[step5]
team = discord.utils.get(message.author.guild.roles,id=int(step4))
if [FO, GM, HC, AC] in message.author.roles:
for guys in server.members:
if guys.id==signeeid:
await guys.add_roles(FA)
await guys.remove_roles(team)
roster.append(guys)
roster_size=str(len(roster))
SignEmbed= discord.Embed(title="KFG Transactions", description=None, color=discord.Color.green())
SignEmbed.add_field(name='Successful Transaction.', value=signee+" has been released from the "+str(emote)+" "+teamname+"!")
SignEmbed.add_field(name="Roster Size is now ", value=roster_size+'/20', inline=True)
await message.channel.send(embed=SignEmbed)
async def on_message5(message, member:discord.Member=None):
if "promote" in message.content:
signer=message.author
signee=message.mentions[0].mention
signeeid=message.mentions[0].id
server=bot.get_guild(801206329049612288)
teamsidslist=[801217912689393714, 801218094814986300, 801224104086208513, 801224243115196426, 801218409878519849, 801222227479625758, 801217334395011113, 801224558589378570, 801222379682005035, 801224701128343662, 801222478646476820, 801222668128747540, 801224835032285225, 801225075231031316, 801225211306967080, 801225374369185793, 801225554199576627, 801225700283121674, 801222743030104104, 801225798408732692, 801222852132995132, 801225991242514473, 801222923746148392, 801223092298186782, 801226082207924244, 801223311081996288, 801226241948647496, 801223486973542451, 801223635858882562, 801223809340276745, 801226427890139137, 801223952344416337]
teamnames=['Arizona Cardinals', 'Atlanta Falcons', 'Baltimore Ravens', 'Buffalo Bills', 'Carolina Panthers', 'Chicago Bears', 'Cincinnati Bengals', 'Cleveland Browns', 'Dallas Cowboys', 'Denver Broncos', 'Detroit Lions', 'Green Bay Packers', 'Houston Texans', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Miami Dolphins', 'Los Angeles Chargers', 'Kansas City Chiefs', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Las Vegas Raiders', 'Los Angeles Chargers', 'Los Angeles Rams', 'Miami Dolphins', 'Minnesota Vikings', 'New England Patriots','New Orleans Saints', 'New York Giants', 'New York Jets', 'Philidelphia Eagles', 'Pittsburgh Steelers', 'San Fransisco 49ers', 'Seattle Seahawks', 'Tampa Bay Buccaneers', 'Tennesse Titans', 'Washington Football Team']
teamemojis=['Arizona_Cardinals', 'Atlanta_Falcons', 'Baltimore_Ravens', 'Buffalo_Bills', 'Carolina_Panthers', 'Chicago_Bears', 'Cincinnati_Bengals', 'Cleveland_Browns', 'Dallas_Cowboys', 'Denver_Broncos', 'Detroit_Lions', 'Green_Bay_Packers', 'Houston_Texans', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Miami_Dolphins', 'Los_Angeles_Chargers', 'Kansas_City_Chiefs', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Las_Vegas_Raiders', 'Los_Angeles_Chargers', 'Los_Angeles_Rams', 'Miami_Dolphins', 'Minnesota_Vikings', 'New_England_Patriots', 'New_Orleans_Saints', 'New_York_Giants', 'New_York_Jets', 'Philidelphia_Eagles', 'Pittsburgh_Steelers', 'San_Francisco_49ers', 'Seattle_Seahawks', 'Tampa_Bay_Buccaneers', 'Tennessee_Titans', 'Washington_Football_Team']
FO = discord.utils.get(message.author.guild.roles, id=801257262240235530)
GM = discord.utils.get(message.author.guild.roles, id=801257315620749362)
HC = discord.utils.get(message.author.guild.roles, id=801257358751694848)
AC = discord.utils.get(message.author.guild.roles, id=801257421334904872)
staffroles = [GM, HC, AC]
teams=[]
roster=[]
for rolesids in message.author.roles:
if rolesids.id in teamsidslist:
teams.append(rolesids.id)
step2=str(staffroles)
step3=step2.replace("[","")
step4=step3.replace("]","")
print(step4)
step5=teamsidslist.index(int(step4))
print(step5)
emote=discord.utils.get(server.emojis,name=teamemojis[step5])
teamname=teamnames[step5]
team = discord.utils.get(message.author.guild.roles,id=int(step4))
if FO in message.author.roles:
for guys in server.members:
if guys.id==signeeid:
await guys.add_roles(staffroles)
embedpromoted = discord.Embed(title='KFG Transactions', description=None)
embedpromoted.add_field(name="The "+teamname+ " have made a promotion!", value="Congratulations to "+signee+" as the "+str(emote)+teamname+ " has promoted them to "+staffroles+".")
await message.channel.send(embed=embedpromoted)
#bot.event
async def on_message4(message, member:discord.Member=None):
if "demote" in message.content:
signer=message.author
signee=message.mentions[0].mention
signeeid=message.mentions[0].id
server=bot.get_guild(801206329049612288)
teamsidslist=[801217912689393714, 801218094814986300, 801224104086208513, 801224243115196426, 801218409878519849, 801222227479625758, 801217334395011113, 801224558589378570, 801222379682005035, 801224701128343662, 801222478646476820, 801222668128747540, 801224835032285225, 801225075231031316, 801225211306967080, 801225374369185793, 801225554199576627, 801225700283121674, 801222743030104104, 801225798408732692, 801222852132995132, 801225991242514473, 801222923746148392, 801223092298186782, 801226082207924244, 801223311081996288, 801226241948647496, 801223486973542451, 801223635858882562, 801223809340276745, 801226427890139137, 801223952344416337]
teamnames=['Arizona Cardinals', 'Atlanta Falcons', 'Baltimore Ravens', 'Buffalo Bills', 'Carolina Panthers', 'Chicago Bears', 'Cincinnati Bengals', 'Cleveland Browns', 'Dallas Cowboys', 'Denver Broncos', 'Detroit Lions', 'Green Bay Packers', 'Houston Texans', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Miami Dolphins', 'Los Angeles Chargers', 'Kansas City Chiefs', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Las Vegas Raiders', 'Los Angeles Chargers', 'Los Angeles Rams', 'Miami Dolphins', 'Minnesota Vikings', 'New England Patriots','New Orleans Saints', 'New York Giants', 'New York Jets', 'Philidelphia Eagles', 'Pittsburgh Steelers', 'San Fransisco 49ers', 'Seattle Seahawks', 'Tampa Bay Buccaneers', 'Tennesse Titans', 'Washington Football Team']
teamemojis=['Arizona_Cardinals', 'Atlanta_Falcons', 'Baltimore_Ravens', 'Buffalo_Bills', 'Carolina_Panthers', 'Chicago_Bears', 'Cincinnati_Bengals', 'Cleveland_Browns', 'Dallas_Cowboys', 'Denver_Broncos', 'Detroit_Lions', 'Green_Bay_Packers', 'Houston_Texans', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Miami_Dolphins', 'Los_Angeles_Chargers', 'Kansas_City_Chiefs', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Las_Vegas_Raiders', 'Los_Angeles_Chargers', 'Los_Angeles_Rams', 'Miami_Dolphins', 'Minnesota_Vikings', 'New_England_Patriots', 'New_Orleans_Saints', 'New_York_Giants', 'New_York_Jets', 'Philidelphia_Eagles', 'Pittsburgh_Steelers', 'San_Francisco_49ers', 'Seattle_Seahawks', 'Tampa_Bay_Buccaneers', 'Tennessee_Titans', 'Washington_Football_Team']
FO = discord.utils.get(message.author.guild.roles, id=801257262240235530)
GM = discord.utils.get(message.author.guild.roles, id=801257315620749362)
HC = discord.utils.get(message.author.guild.roles, id=801257358751694848)
AC = discord.utils.get(message.author.guild.roles, id=801257421334904872)
staffroles = [GM, HC, AC]
teams=[]
roster=[]
for rolesids in message.author.roles:
if rolesids.id in teamsidslist:
teams.append(rolesids.id)
step2=str(staffroles)
step3=step2.replace("[","")
step4=step3.replace("]","")
print(step4)
step5=teamsidslist.index(int(step4))
print(step5)
emote=discord.utils.get(server.emojis,name=teamemojis[step5])
teamname=teamnames[step5]
team = discord.utils.get(message.author.guild.roles,id=int(step4))
if FO in message.author.roles:
for guys in server.members:
if guys.id==signeeid:
await guys.remove_roles(staffroles)
embedpromoted = discord.Embed(title='KFG Transactions', description=None)
embedpromoted.add_field(name="The "+teamname+ " has made a demotion.", value='Tough luck for '+signee+' as they have been demoted from their spot as '+staffroles+'on the '+str(emote)+teamname+'.', inline=True)
await message.channel.send(embed=embedpromoted)
#bot.command()
async def rostercount(ctx, member:discord.Member=None):
server=bot.get_guild(801206329049612288)
teamsidslist=[801217912689393714, 801218094814986300, 801224104086208513, 801224243115196426, 801218409878519849, 801222227479625758, 801217334395011113, 801224558589378570, 801222379682005035, 801224701128343662, 801222478646476820, 801222668128747540, 801224835032285225, 801225075231031316, 801225211306967080, 801225374369185793, 801225554199576627, 801225700283121674, 801222743030104104, 801225798408732692, 801222852132995132, 801225991242514473, 801222923746148392, 801223092298186782, 801226082207924244, 801223311081996288, 801226241948647496, 801223486973542451, 801223635858882562, 801223809340276745, 801226427890139137, 801223952344416337]
teamnames=['Arizona Cardinals', 'Atlanta Falcons', 'Baltimore Ravens', 'Buffalo Bills', 'Carolina Panthers', 'Chicago Bears', 'Cincinnati Bengals', 'Cleveland Browns', 'Dallas Cowboys', 'Denver Broncos', 'Detroit Lions', 'Green Bay Packers', 'Houston Texans', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Miami Dolphins', 'Los Angeles Chargers', 'Kansas City Chiefs', 'Indianapolis Colts', 'Jacksonville Jaguars', 'Kansas City Chiefs', 'Las Vegas Raiders', 'Los Angeles Chargers', 'Los Angeles Rams', 'Miami Dolphins', 'Minnesota Vikings', 'New England Patriots','New Orleans Saints', 'New York Giants', 'New York Jets', 'Philidelphia Eagles', 'Pittsburgh Steelers', 'San Fransisco 49ers', 'Seattle Seahawks', 'Tampa Bay Buccaneers', 'Tennesse Titans', 'Washington Football Team']
teamemojis=['Arizona_Cardinals', 'Atlanta_Falcons', 'Baltimore_Ravens', 'Buffalo_Bills', 'Carolina_Panthers', 'Chicago_Bears', 'Cincinnati_Bengals', 'Cleveland_Browns', 'Dallas_Cowboys', 'Denver_Broncos', 'Detroit_Lions', 'Green_Bay_Packers', 'Houston_Texans', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Miami_Dolphins', 'Los_Angeles_Chargers', 'Kansas_City_Chiefs', 'Indianaoplis_Colts', 'Jacksonville_Jaguars', 'Kansas_City_Chiefs', 'Las_Vegas_Raiders', 'Los_Angeles_Chargers', 'Los_Angeles_Rams', 'Miami_Dolphins', 'Minnesota_Vikings', 'New_England_Patriots', 'New_Orleans_Saints', 'New_York_Giants', 'New_York_Jets', 'Philidelphia_Eagles', 'Pittsburgh_Steelers', 'San_Francisco_49ers', 'Seattle_Seahawks', 'Tampa_Bay_Buccaneers', 'Tennessee_Titans', 'Washington_Football_Team']
roster=[]
teams=[]
roster=[]
step2=str(teams)
step3=step2.replace("[","")
step4=step3.replace("]","")
print(step4)
step5=teamsidslist.index(int(step4))
print(step5)
emote=discord.utils.get(server.emojis,name=teamemojis[step5])
teamname=teamnames[step5]
team = discord.utils.get(ctx.author.guild.roles,id=int(step4))
for guys in server.members:
await asyncio.sleep(1)
roster_size=(len(roster))
teamlist = discord.Embed(title=+str(emote)+teamname+"'s roster count:")
teamlist.add_field(name=roster_size, value=str(emote)+teamname+f"'s roster count - brought up by {ctx.author}")
await ctx.send(embed=teamlist)
#bot.event
async def on_command_error(ctx, error):
print(f"Some idiot raised an error at {timestamp} - it was {ctx.author}: {error}")
raise error
keep_alive()
bot.run(os.getenv('kfgbottoken'))
You cannot create more than one on_message event. Only the last one will work. Also, you have to add bot.process_commands(message) to the last line of on_message event. Otherwise it prevents commands from running.
#bot.event
async def on_message(message):
...
await bot.process_commands(message)
All you have to do is putting all your on_message events in just one.
Related
Roster count on discord.py dysfunctional
When signing a player to a team, bot doesn't print a roster count, and just says 0. #bengals.event #commands.has_any_role('Franchise Owner', 'General Manager', 'Head Coach', 'Assistant Coach') async def on_message(message, *, user:discord.Member=None): if '<:Cincinnati_Bengals:801216801425457153> sign' in message.content: signee=message.mentions[0].mention signeeid=message.mentions[0].id guild = bengals.get_guild(801206329049612288) bengalrole = discord.utils.get(guild.roles, name="Cincinnati Bengals") freerole = discord.utils.get(guild.roles, name="✨ League Membership") rostercount = len(bengalrole.members) embedsigned = discord.Embed(title="KFG Transaction Complete", description=signee+" has been signed to the <:Cincinnati_Bengals:801216801425457153> Cincinnati Bengals.", color = discord.Color.green()) embedsigned.add_field(name=f'<:Cincinnati_Bengals:801216801425457153> Cincinnati Bengals new roster count is **{rostercount}**.', value="KFG Transaction") await message.channel.send(embed=embedsigned) for guys in server.members: if guys.id==signeeid: await guys.add_roles(bengalrole) await guys.remove_roles(freerole)
Django Rest Framework: Serializing splits list of strings into list of characters
I am setting up an API with DRF, everything is going smoothly but I am having a bit of a problem when passing a field with a list of strings Json object { "postID": 1, "index": 0, "text": "For years you had a President who apologized for America – now you have a President who is standing up for America, and standing up for PENNSYLVANIA. Tomorrow, you have the power, with your vote, to save AMERICA! GET OUT AND VOTE!! #MAGA ", "date": "2020-11-02", "likesCount": 145000, "commentsCount": 4500, "sharesCount": 3500, "hashtags": [ "[", "'", "M", "A", "G", "A", "'", " ", "'" "A", "G", "A", "I", "N", "'", "]" ] } Whereas hashtags field values should be: "['MAGA' , 'AGAIN']". How could I override the serializer and prevent that strings are split into characters ? models.py from djongo import models from django.contrib.postgres.fields import ArrayField # Create your models here. class Post(models.Model): index = models.IntegerField() postID = models.IntegerField(primary_key=True) text = models.CharField(max_length=500) date = models.DateField() likesCount = models.IntegerField() commentsCount = models.IntegerField() sharesCount = models.IntegerField() hashtags = ArrayField(models.CharField(max_length=20, blank=True), size=50) tokens = ArrayField(models.CharField(max_length=20, blank=True), size=50) tagged = ArrayField(models.CharField(max_length=20, blank=True), size=50) keywords = ArrayField(models.CharField(max_length=20, blank=True), size=50) entities = ArrayField(models.CharField(max_length=20, blank=True), size=50) noun_phrases = ArrayField(models.CharField(max_length=20, blank=True), size=50) noun_phrases_keywords = ArrayField(models.CharField(max_length=20, blank=True), size=50) serializer.py from rest_framework import serializers from .models import Post, Comments class PostSerializer(serializers.ModelSerializer): class Meta: model = Post fields = '__all__' Serializer inspection PostSerializer(): postID = IntegerField(label='PostID', max_value=2147483647, min_value=-2147483648, validators=[<UniqueValidator(queryset=Post.objects.all())>]) index = IntegerField(max_value=2147483647, min_value=-2147483648) text = CharField(max_length=500) date = DateField() likesCount = IntegerField(label='LikesCount', max_value=2147483647, min_value=-2147483648) commentsCount = IntegerField(label='CommentsCount', max_value=2147483647, min_value=-2147483648) sharesCount = IntegerField(label='SharesCount', max_value=2147483647, min_value=-2147483648) hashtags = ListField(allow_empty=False, child=CharField(allow_blank=True, label='Hashtags', max_length=20, required=False), validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>]) tokens = ListField(allow_empty=False, child=CharField(allow_blank=True, label='Tokens', max_length=20, required=False), validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>]) tagged = ListField(allow_empty=False, child=CharField(allow_blank=True, label='Tagged', max_length=20, required=False), validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>]) keywords = ListField(allow_empty=False, child=CharField(allow_blank=True, label='Keywords', max_length=20, required=False), validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>]) entities = ListField(allow_empty=False, child=CharField(allow_blank=True, label='Entities', max_length=20, required=False), validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>]) noun_phrases = ListField(allow_empty=False, child=CharField(allow_blank=True, label='Noun phrases', max_length=20, required=False), validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>]) noun_phrases_keywords = ListField(allow_empty=False, child=CharField(allow_blank=True, label='Noun phrases keywords', max_length=20, required=False), validators=[<django.contrib.postgres.validators.ArrayMaxLengthValidator object>])
I got to a solution using DRF serialize ArrayField as string as a reference :). serializer.py class StringArrayField(ListField): def to_representation(self, obj): # convert list to string return "".join([str(element) for element in obj]) def to_internal_value(self, data): data = data.split(",") # convert string to list return super().to_internal_value(self, data)
on_raw_reaction_add is not working with ctx and its attribute "author"
Hey I have this Problem where i can't use the ctx attribute author. So my Questen is, is there another way to create a channel in discord.py that works with on_reaction_add. My Eror is: Ignoring exception in on_raw_reaction_add Traceback (most recent call last): File "C:\dev\Python\Einführung\venv\lib\site-packages\discord\client.py", line 333, in _run_event await coro(*args, **kwargs) File "C:/Users/bmichs/Desktop/Ticketbot_Simon_2.py", line 501, in on_raw_reaction_add async def Vorgefertigtenachricht(ctx): File "C:/Users/bmichs/Desktop/Ticketbot_Simon_2.py", line 439, in berechtigung ticket_number = int(data["ticket-counter"]) AttributeError: 'RawReactionActionEvent' object has no attribute 'author' #bot.event async def on_raw_reaction_add(ctx): with open("data.json") as f: data = json.load(f) user = ctx.author ticket_number = int(data["ticket-counter"]) ticket_number += 1 ticket_channel = await ctx.guild.create_text_channel("ticket-{}".format(ticket_number)) await ticket_channel.set_permissions(ctx.guild.get_role(ctx.guild.id), send_messages=False, read_messages=False) for role_id in data["valid-roles"]: role = ctx.guild.get_role(role_id) await ticket_channel.set_permissions(role, send_messages=True, read_messages=True, add_reactions=True, embed_links=True, attach_files=True, read_message_history=True, external_emojis=True) await ticket_channel.set_permissions(user, send_messages=True, read_messages=True, add_reactions=True, embed_links=True, attach_files=True, read_message_history=True, external_emojis=True) await ticket_channel.set_permissions(user, send_messages=True, read_messages=True, add_reactions=True, embed_links=True, attach_files=True, read_message_history=True, external_emojis=True) em = discord.Embed(title="Ticket Erstellt von {}#{}".format(ctx.user.name, ctx.user.discriminator), description="{}".format(message_content), color=0xf1c40f) em2 = discord.Embed(title="Guten Tag {}".format(ctx.user.name), description="Willkommen im Ticket Support. Wir bitten dich dein Problem so ausführlich wie möglich uns mitzuteilen. Wir bitten dich ein wenig Geduld zu haben. \nWir werden dein Ticket so schnellst wie möglich bearbeiten.", color=0xad1457) await ticket_channel.send(embed=em) await ticket_channel.send(embed=em2) pinged_msg_content = "" non_mentionable_roles = [] if data["pinged-roles"] != []: for role_id in data["pinged-roles"]: role = ctx.guild.get_role(role_id) pinged_msg_content += role.mention pinged_msg_content += " " if role.mentionable: pass else: await role.edit(mentionable=True) non_mentionable_roles.append(role) await ticket_channel.send(pinged_msg_content) for role in non_mentionable_roles: await role.edit(mentionable=False) data["ticket-channel-ids"].append(ticket_channel.id) data["ticket-counter"] = int(ticket_number) with open("data.json", 'w') as f: json.dump(data, f) created_em = discord.Embed(title="Ticket Support:", description="Dein Ticket wurde erfolgreich erstellt! **{}**".format( ticket_channel), color=0xad1457) await ctx.send(embed=created_em)
You can use on_raw_reaction_add but that takes a payload not ctx Here is an example with some parameters to use #bot.event async def on_raw_reaction_add(payload): channel = bot.get_channel(payload.channel_id) # skip DM messages if isinstance(channel, discord.DMChannel): return message = await channel.fetch_message(payload.message_id) guild = bot.get_guild(payload.guild_id) user = guild.get_member(payload.user_id) emoji = payload.emoji.name reaction = discord.utils.get(message.reactions, emoji=emoji) payload
Have two users challenge each other using reactions discord.py
I would like two users to challenge each other to be able to use reactions so if you can only have one command to use. Using the command tfo #user I would like you to send a private message to the user with the possibility of clicking one of the two reactions to accept or reject the challenge having a time limit that in case it is not executed in time cancels the challenge request and will send another private message (to both of you). I know that to do this I should use await client.wait_for but I don't know how to use it for reactions. This is the code I used for the version against the bot #client.command(aliases=["TFO"]) async def tenta_la_fortuna_offline(ctx, amount : int): id = str(ctx.message.author.id) amounts[id] -= amount if amounts[id] < 0: await ctx.send(f"Non hai abbastanza soldi per giocare.") amounts[id] += amount return if amount < 99: await ctx.send("Puoi puntare da 100 in poi") return if not amount: await ctx.send("Aggiungi quanti soldi vuoi puntare") return if id not in amounts: await ctx.send("Hai bisogno di un account per giocare") return utente = [ ('Sei salvo!', 'salvo',), ('Sei a rischio eliminazione!', 'rischio',), ('Sei __ELIMINATO__!', 'eliminato'), ('Hai __~~VINTO~~__!', 'vinto'), ('Sei a rischio eliminazione!', 'rischio',), ] bot = [ ('Sei salvo!', 'salvo',), ('Sei a rischio eliminazione!', 'rischio',), ('Sei __ELIMINATO__!', 'eliminato'), ('Hai __~~VINTO~~__!', 'vinto'), ('Sei a rischio eliminazione!', 'rischio',), ] embed = discord.Embed( title="**Tenta la Fortuna - Offline**", description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!", color=0x003399 ) embed.set_thumbnail(url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png') embed.add_field( name="**Utente**", value="** **", inline=True ) embed.add_field( name="**Bot**", value="** **", inline=True ) message = await ctx.send(embed=embed) win = int(amount * 2) await asyncio.sleep(1) for numero in range(1,101): u_uscita, u_condizione = random.choice(utente) embed.clear_fields() if u_condizione == "eliminato": embed = discord.Embed( title="**Tenta la Fortuna - Offline**", description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!", color=0xFF0000 ) embed.set_thumbnail( url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png' ) embed.set_footer( text=f"Round numero {numero}" ) embed.add_field( name="**Utente**", value=f"{u_uscita}", inline=True ) embed.add_field( name="**Bot**", value="** **", inline=True ) await message.edit(embed=embed) return if u_condizione == "vinto": embed = discord.Embed( title="**Tenta la Fortuna - Offline**", description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!", color=0x00FF00 ) embed.set_thumbnail( url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png' ) embed.set_footer( text=f"Round numero {numero}" ) embed.add_field( name="**Utente**", value=f"{u_uscita}", inline=True ) embed.add_field( name="**Bot**", value="** **", inline=True ) await message.edit(embed=embed) amounts[id] += win return embed.set_footer( text=f"Round numero {numero}" ) embed.add_field( name="**Utente**", value=f"{u_uscita}", inline=True ) embed.add_field( name="**Bot**", value="** **", inline=True ) await message.edit(embed=embed) await asyncio.sleep(0.5) b_uscita, b_condizione = random.choice(bot) embed.clear_fields() if b_condizione == "vinto": embed = discord.Embed( title="**Tenta la Fortuna - Offline**", description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!", color=0xFF0000 ) embed.set_thumbnail( url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png' ) embed.set_footer( text=f"Round numero {numero}" ) embed.add_field( name="**Utente**", value=f"{u_uscita}", inline=True ) embed.add_field( name="**Bot**", value=f"{b_uscita}", inline=True ) await message.edit(embed=embed) return if u_condizione == "rischio": if b_condizione == "salvo": embed = discord.Embed( title="**Tenta la Fortuna - Offline**", description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!", color=0xFF0000 ) embed.set_thumbnail( url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png' ) embed.set_footer( text=f"Round numero {numero}" ) embed.add_field( name="**Utente**", value=f"{u_uscita}", inline=True ) embed.add_field( name="**Bot**", value=f"{b_uscita}", inline=True ) await message.edit(embed=embed) return if b_condizione == "eliminato": embed = discord.Embed( title="**Tenta la Fortuna - Offline**", description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!", color=0x00FF00 ) embed.set_thumbnail( url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png' ) embed.set_footer( text=f"Round numero {numero}" ) embed.add_field( name="**Utente**", value=f"{u_uscita}", inline=True ) embed.add_field( name="**Bot**", value=f"{b_uscita}", inline=True ) await message.edit(embed=embed) amounts[id] += amount return if b_condizione == "rischio": if u_condizione == "salvo": embed = discord.Embed( title="**Tenta la Fortuna - Offline**", description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!", color=0x00FF00 ) embed.set_thumbnail( url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png' ) embed.set_footer( text=f"Round numero {numero}" ) embed.add_field( name="**Utente**", value=f"{u_uscita}", inline=True ) embed.add_field( name="**Bot**", value=f"{b_uscita}", inline=True ) await message.edit(embed=embed) amounts[id] += win return embed.set_footer( text=f"Round numero {numero}" ) embed.add_field( name="**Utente**", value=f"{u_uscita}", inline=True ) embed.add_field( name="**Bot**", value=f"{b_uscita}", inline=True ) await message.edit(embed=embed) await asyncio.sleep(1) if numero == 100: embed = discord.Embed( title="**Tenta la Fortuna - Offline**", description="Affronta il nostro bot per poter vincere il doppio dei soldi scommessi!", color=0xDBA901 ) embed.set_thumbnail( url='https://cdn.discordapp.com/attachments/640563710104043530/731596857868025886/TENTA_LA_FORTUNA.png' ) embed.set_footer( text=f"Round numero {numero}" ) embed.add_field( name="**Utente**", value=f"{u_uscita}", inline=True ) embed.add_field( name="**Bot**", value=f"{b_uscita}", inline=True ) await message.edit(embed=embed)
Your code fragment is huge & in another language so I can't help you directly (as I have no idea what's going on), but this is how to use wait_for with reactions: #client.event async def on_message(message): if message.content.startswith('$thumb'): channel = message.channel await channel.send('Send me that 👍 reaction, mate') def check(reaction, user): return user == message.author and str(reaction.emoji) == '👍' try: reaction, user = await client.wait_for('reaction_add', timeout=60.0, check=check) except asyncio.TimeoutError: await channel.send('👎') else: await channel.send('👍') Fragment taken out of the API Docs for wait_for, shows how to wait for a 👍 reaction & do something with it. In case the user doesn't add the reaction within the timeout (here 60 seconds), it will throw a TimeoutError and send 👎. You can modify this to fit your needs & put it in your command where it fits.
Can I manually add to InclusiveNamespaces PrefixList in WSS4J
I am using WSS4J 2.1.10 to sign a soap message with a timestamp. The service I am sending the message to is requiring that I 1) include the namespace "http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512" in the Signature, Timestamp and BST elements 2) add the "wsu" namespace to the InclusiveNamespaces PrefixList for the Transform for the Timestamp Element like such: <ds:Reference URI="#TS-634a1acd-e8fd-4629-a19a-1935e677797b"> <ds:Transforms> <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"> <ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="wsu wsse env"/> </ds:Transform> </ds:Transforms> <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> <ds:DigestValue>uDqH4tK4HcsJWOit+DUW8llsEk8=</ds:DigestValue> </ds:Reference> 3) add the "wsse" namespace to the InclusiveNamespaces PrefixList for CanonicalizationMethod for the Signature Element like such: <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"> <ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="wsse env"/> </ds:CanonicalizationMethod> Can anyone tell me if this is possible and how? My code so far is: WSSConfig.init(); SOAPMessage soapMessage = getSoapMessage(); SOAPHeader soapHeader = soapMessage.getSOAPHeader(); Name toHeaderName = soapFactory.createName("To", "", "http://www.w3.org/2005/08/addressing"); SOAPHeaderElement toHeader = soapHeader.addHeaderElement(toHeaderName); toHeader.setAttributeNS(WSConstants.WSU_NS, WSConstants.WSU_PREFIX + ":Id", "_5002");//TODO: Does this need to be a fixed value? Attr idAttr = toHeader.getAttributeNode(WSConstants.WSU_PREFIX + ":Id"); toHeader.setIdAttributeNode(idAttr, true); toHeader.setTextContent(vgEndpoint); Name actionHeaderName = soapFactory.createName("Action", "", "http://www.w3.org/2005/08/addressing"); SOAPHeaderElement actionHeader = soapHeader.addHeaderElement(actionHeaderName); actionHeader.setTextContent("http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue"); actionHeader.setMustUnderstand(true); Name replyToHeaderName = soapFactory.createName("ReplyTo", "", "http://www.w3.org/2005/08/addressing"); SOAPHeaderElement replyToHeader = soapHeader.addHeaderElement(replyToHeaderName); Name rtAddressName = soapFactory.createName("Address"); SOAPElement rtAddress = replyToHeader.addChildElement(rtAddressName); rtAddress.setTextContent("http://www.w3.org/2005/08/addressing/anonymous"); Name faultToHeaderName = soapFactory.createName("FaultTo", "", "http://www.w3.org/2005/08/addressing"); SOAPHeaderElement faultToHeader = soapHeader.addHeaderElement(faultToHeaderName); Name ftAddressName = soapFactory.createName("Address"); SOAPElement ftAddress = faultToHeader.addChildElement(ftAddressName); ftAddress.setTextContent("http://www.w3.org/2005/08/addressing/anonymous"); Name messageIdName = soapFactory.createName("MessageID", "", "http://www.w3.org/2005/08/addressing"); SOAPHeaderElement messageIdHeader = soapHeader.addHeaderElement(messageIdName); messageIdHeader.setTextContent("uuid:" + UUID.randomUUID().toString()); Name secHeaderName = soapFactory.createName(WSConstants.WSSE_LN, WSConstants.WSSE_PREFIX, WSConstants.WSSE_NS); SOAPHeaderElement secHeader = soapHeader.addHeaderElement(secHeaderName); secHeader.addNamespaceDeclaration("wsc", "http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512"); secHeader.setMustUnderstand(true); Merlin crypto = getCrypto(privateKey, password, salt, certChain); Document unsignedDocument = soapMessage.getSOAPPart().getEnvelope().getOwnerDocument(); WSSecHeader wsSecHeader = new WSSecHeader(unsignedDocument); wsSecHeader.insertSecurityHeader(); WSSecTimestamp timestamp = new WSSecTimestamp(); timestamp.setPrecisionInMilliSeconds(false); timestamp.setTimeToLive(600); timestamp.build(unsignedDocument, wsSecHeader); // Setup the signer WSSecSignature signer = new WSSecSignature(); signer.setUserInfo("signingCert", password); signer.setSignatureAlgorithm(WSConstants.RSA_SHA1); signer.setDigestAlgo(WSConstants.SHA1); signer.setSigCanonicalization(WSConstants.C14N_EXCL_OMIT_COMMENTS); signer.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); signer.setAddInclusivePrefixes(true); signer.setUseSingleCertificate(true); signer.getParts().add(new WSEncryptionPart("Timestamp", WSConstants.WSU_NS, null)); signer.getParts().add(new WSEncryptionPart("To", "http://www.w3.org/2005/08/addressing", null)); signer.build(unsignedDocument, crypto, wsSecHeader); And here is the resultant Soap Message obviously missing these 3 points: <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"> <env:Header> <To xmlns="http://www.w3.org/2005/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="_5002">https://localhost/service.svc</To> <Action xmlns="http://www.w3.org/2005/08/addressing" env:mustUnderstand="true">http://docs.oasis-open.org/ws-sx/ws-trust/200512/RST/Issue</Action> <ReplyTo xmlns="http://www.w3.org/2005/08/addressing"> <Address>http://www.w3.org/2005/08/addressing/anonymous</Address> </ReplyTo> <FaultTo xmlns="http://www.w3.org/2005/08/addressing"> <Address>http://www.w3.org/2005/08/addressing/anonymous</Address> </FaultTo> <MessageID xmlns="http://www.w3.org/2005/08/addressing">uuid:dc08272f-609f-47e3-ac9b-6049a98a0dab</MessageID> <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" env:mustUnderstand="true"> <wsse:BinarySecurityToken EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" wsu:Id="X509-848ca3b0-a273-4cbf-ae1a-e34dc570444e">*** REMOVED ***</wsse:BinarySecurityToken> <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#" Id="SIG-25253839-097b-495a-ae60-24fa8a5f0ada"> <ds:SignedInfo> <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"> <ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="env"/> </ds:CanonicalizationMethod> <ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/> <ds:Reference URI="#TS-634a1acd-e8fd-4629-a19a-1935e677797b"> <ds:Transforms> <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"> <ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="wsse env"/> </ds:Transform> </ds:Transforms> <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> <ds:DigestValue>uDqH4tK4HcsJWOit+DUW8llsEk8=</ds:DigestValue> </ds:Reference> <ds:Reference URI="#_5002"> <ds:Transforms> <ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"> <ec:InclusiveNamespaces xmlns:ec="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="env"/> </ds:Transform> </ds:Transforms> <ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/> <ds:DigestValue>LiNgJUCK0GyrUZ3BpbdlRbVKnfo=</ds:DigestValue> </ds:Reference> </ds:SignedInfo> <ds:SignatureValue>l8EyofVcLesFD1c6btPu2zJ6dTRTyqCSWy7aW7MVH4x3nWh3y0Ir7xY2nNSZeXpcc5Q/7wrWOVgX+TkT/zwEVL62hpq4HyUJb/aIwTDhUIlH5UL7UeudDCRvvAnPOtzEp/jnapKUbsJpIzXWmvlS6tB2E3SUDT/MChradRcawJ0=</ds:SignatureValue> <ds:KeyInfo Id="KI-c2995ba4-6fe5-457c-9367-25c5d98eff91"> <wsse:SecurityTokenReference wsu:Id="STR-4bc8eb55-9b1f-4bb8-a7cc-d4685bd3aa2c"> <wsse:Reference URI="#X509-848ca3b0-a273-4cbf-ae1a-e34dc570444e" ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"/> </wsse:SecurityTokenReference> </ds:KeyInfo> </ds:Signature> <wsu:Timestamp wsu:Id="TS-634a1acd-e8fd-4629-a19a-1935e677797b"> <wsu:Created>2017-07-11T02:38:06Z</wsu:Created> <wsu:Expires>2017-07-11T02:48:06Z</wsu:Expires> </wsu:Timestamp> </wsse:Security> </env:Header> <env:Body/> </env:Envelope>
i did so List<String> prefixList = new ArrayList<String>(); prefixList.add("ser soapenv"); sigFactory.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE,new ExcC14NParameterSpec(prefixList)); Result <ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"> <InclusiveNamespaces xmlns="http://www.w3.org/2001/10/xml-exc-c14n#" PrefixList="ser soapenv"/> </ds:CanonicalizationMethod> The sample https://docs.oracle.com/cd/E17802_01/webservices/webservices/docs/2.0/xmldsig/api/javax/xml/crypto/doc-files/SignedSoap.java